Ok. Begineer question again:
I seem to be able to open my db connection. Now, how do I assign the result of the SQL query to a variable so I can then compare the answer with what I am expecting? I am not sure what I should put around the part in Bold. Thanks
Here is the script:
VBSTART
Dim SQLString
set MyDB = CreateObject("ADODB.Connection")
' MyDB.CursorLocation = adUseServer
MyDB.Open "Provider=ASAProv;Data Source=C:\Database\sm_3.db;" & _
"User Id=dba;Password=sql;"
SQLString = "Select * from dba.system_settings where setting_name = 'SITE_ID'"
Set RS = MyDB
MyDB.Close
Set MyDB = nothing
VBEND
VB Help Needed
Moderators: Dorian (MJT support), JRL
- Marcus Tettmar
- Site Admin
- Posts: 7395
- Joined: Thu Sep 19, 2002 3:00 pm
- Location: Dorset, UK
- Contact:
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
- Marcus Tettmar
- Site Admin
- Posts: 7395
- Joined: Thu Sep 19, 2002 3:00 pm
- Location: Dorset, UK
- Contact:
Well you can narrow down your search - VB is NOT VBScript. So look at sites specific to VBScript not VB.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
Here is what is working right now. I do not understand that line:
GetCustomerName = claude.Fields("setting_value")
In fact, I understand the right part, not the left part. Why are we assigning the result of claude.Fields("setting_value") to GetCustomerName IF GetCustomerName IS the name of the function itself?
What a beginner question hein?
==============================================
Function GetCustomerName(guy)
Dim SQLString
set MyDB = CreateObject("ADODB.Connection")
MyDB.Open "Provider=ASAProv;Data Source=C:\Database\sm_3.db;" & _
"User Id=dba;Password=sql;"
SQLString = "select * from dba.system_settings where setting_name = 'SITE_ID'"
set claude = MyDB.Execute(SQLString)
GetCustomerName = claude.Fields("setting_value")
MyDB.Close
Set MyDB = nothing
End Function
VBEND
VBEval>GetCustomerName(guy),CustName
Message> %CustName%
GetCustomerName = claude.Fields("setting_value")
In fact, I understand the right part, not the left part. Why are we assigning the result of claude.Fields("setting_value") to GetCustomerName IF GetCustomerName IS the name of the function itself?
What a beginner question hein?
==============================================
Function GetCustomerName(guy)
Dim SQLString
set MyDB = CreateObject("ADODB.Connection")
MyDB.Open "Provider=ASAProv;Data Source=C:\Database\sm_3.db;" & _
"User Id=dba;Password=sql;"
SQLString = "select * from dba.system_settings where setting_name = 'SITE_ID'"
set claude = MyDB.Execute(SQLString)
GetCustomerName = claude.Fields("setting_value")
MyDB.Close
Set MyDB = nothing
End Function
VBEND
VBEval>GetCustomerName(guy),CustName
Message> %CustName%
- Marcus Tettmar
- Site Admin
- Posts: 7395
- Joined: Thu Sep 19, 2002 3:00 pm
- Location: Dorset, UK
- Contact:
By assigning a value to the function name you are defining the RETURN value of the function. So in this case the function GetCustomerName RETURNS claude.Fields("setting_value"). Therefore when you CALL GetCustomerName (e.g. with the VBEval statement) the value of the function is returned. In this case the value of the function is the value of claude.Fields("setting_value")Why are we assigning the result of claude.Fields("setting_value") to GetCustomerName IF GetCustomerName IS the name of the function itself?
The VBEval statement takes this form:
VBEval>VBScript_Statement,variable
The value returned by VBScript_Statement is put into variable. So if we do:
VBEval>GetCustomerName("1234"),theCustomerName
Then the value returned by the GetCustomerName function is put into the theCustomerName variable. The value returned by GetCustomerName is whatever is assigned to it - in your case claude.Fields("setting_value").
Does that make sense?
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
Ok great. I still have a question though:
Assuming that GetCustomerName = claude.Fields("setting_value") sets the return value of the function, what is the role of the name between the parenthesis themselves of the Function line?
I mean for the following line, what is the role of (guy)?
Function GetCustomerName(guy)
I mean, I can change it to whatever and it still works. That is why I am confuse. Same thing happens with the VBEval statement. I could write
VBEval>GetCustomerName(joebloe) and it will still work! You see the confusion?
Is the name between the parenthesis is just there to say that only 1 parameter is passed to the function?
Thanks for all your help.
Assuming that GetCustomerName = claude.Fields("setting_value") sets the return value of the function, what is the role of the name between the parenthesis themselves of the Function line?
I mean for the following line, what is the role of (guy)?
Function GetCustomerName(guy)
I mean, I can change it to whatever and it still works. That is why I am confuse. Same thing happens with the VBEval statement. I could write
VBEval>GetCustomerName(joebloe) and it will still work! You see the confusion?
Is the name between the parenthesis is just there to say that only 1 parameter is passed to the function?
Thanks for all your help.