Change Label Text Through Loop
I want to display a couple of things from my DB in a single object values named "Text 3" (by example)
I tried a lot of things like :
Dim cn
Dim rs
set cn = CreateObject("ADODB.Connection")
set rs = CreateObject("ADODB.Recordset")
cn.connectionString = "Driver={MySQL ODBC 5.3 ANSI driver};Server=MyIP;Database=MyDB;UID=MyUser;PWD=MyPW;"
cn.open
rs.open "SELECT * from MyTable WHERE MyID = 1", cn, 3
rs.MoveFirst
while not rs.eof
MsgBox rs(0)
rs.MoveNext
wend
cn.close
But there are 3 things I do not know how to proceed to get them working
1) How to get the current value of rs. I want to use the value of rs in my loop instead of using rs(0), rs(1), rs(3)...
2) How to select my object values based on the name. In this case "Text 3". I tried to
Set myText = Objects(“Text 3”)
And then
myText.text = myText.text & rs(0)
But it does not work and I do not know where to find a solution
3) I am asking a number before each print with this :
[attachment=1756:Image_140.png]
It display the following :
[attachment=1757:Image_141.png]
I am asking how to get the value in my VBScript ? Is it possible ? If no, how to get this working ? Because my mySQL query is based on this number
SELECT * from MyTable WHERE MyID = 1
I wrote it manually but I search to do it automatically
I am pretty new to VBScript so sorry for my lack of misscomprehension !
I do not ask for a full fonctional solution but if you could help me even a little I will be so happy. Thanks !
-
Ok, I'm probably even "newer" to VBS than you, but maybe we both can learn something :)
1) So... you don't want to retrieve the value of each individual field of the current record, but the values of all fields of the current record? Have you tried something like:
val = rs.GetString(,1)
2) By "Object Value" you mean the value of a BarTender object (e.g. text element)? Have you tried:
val = Format.Objects("Text 3").Value3) I'm not sure I understand what you mean... You are querying the database based on the QueryPrompt entry (second picture). I assume that the result will be displayed in a BarTender object on the label? If that result is what you need in your VBScript, you should be able to get it by assigning a name to the data source (object properties) and then retrieving the value in VBS using:
val = Format.NamedSubStrings("Whatevernameyouassigned").Value0 -
I get this working with you help.
It look like something like that
Dim cn Dim rs set cn = CreateObject("ADODB.Connection") set rs = CreateObject("ADODB.Recordset") cn.connectionString = "Driver={MySQL ODBC 5.3 ANSI driver};Server=127.0.0.1;Database=;UID=;PWD=;" cn.open rs.open "SELECT something", cn, 3 rs.MoveFirst dim val while not rs.eof val = val & rs.GetString(,1) wend Format.NamedSubStrings("test").Value = val cn.close0 -
In your "While Not" section: Aren't you just adding each line of the entire recordset separately here...? Couldn't you just use "val = rs.GetString()" without the While loop and get the same result?
It seems like your method only really makes sense if you have to do something with each record/line...?
0
Please sign in to leave a comment.
Comments
3 comments