|
-
Sep 11th, 2006, 06:44 AM
#1
Thread Starter
Addicted Member
is it possible to pass variables from a textbox in visual basic?
is it possible to pass variables from a textbox in visual basic?
i am trying to pass a variable from a textbox. eg this is what is contained in a textbox
Hallo " & !Name & ", your current balance is " & !amount & ". please pay this amount to avoid disconnection!!! Customer Service.
the variables contained in the text box are !name and !amount
the app should be able to tell me what is contained in the field amount and name.
-
Sep 11th, 2006, 06:47 AM
#2
PowerPoster
Re: is it possible to pass variables from a textbox in visual basic?
Pass the variables from a textbox that is *where* exactly?
If it's your form, it is simple enough to do this...it's fundamental programming :-P
Well, everyone else has been doing it :-)
Loading a file into memory QUICKLY - Using SendKeys - HyperLabel - A highly customisable label replacement - Using resource files/DLLs with VB - Adding GZip to your projects
Expect more to come in future
If I have helped you, RATE ME! :-)
I love helping noobs with their VB problems (probably because, as an amateur programmer, I am only slightly better at VB than them :-)) but if you SERIOUSLY want to get help for free from a community such as VBForums, you have to first have a grounding (basic knowledge) in VB6, otherwise you're way too much work to help...You've got to give a little if you want to get help from us, in other words!
And we DON'T do your homework. If your tutor doesn't teach you enough to help you make the project without his or her help, FIND A BETTER TUTOR or try reading books on programming! We are happy to help with minor things regarding the project, but you have to understand the rest of it if you want our help to be useful.
-
Sep 11th, 2006, 06:54 AM
#3
Thread Starter
Addicted Member
Re: is it possible to pass variables from a textbox in visual basic?
Yes from my form. can u show me how to do this. below is the code am using but it doesnt pull the variables. it just returns the same string that is contained in the textbox
VB Code:
Set SQLINTERGRATION = New ADODB.Recordset
Dim sTemp As String
If txtsql.Text = "" Then
MsgBox "Please specify the sql string to be executed", vbInformation, "Error"
Exit Sub
End If
SQLINTERGRATION.Open "" & txtsql.Text & "", gConnection, adOpenDynamic, adLockOptimistic
Set DGINtergartion.DataSource = SQLINTERGRATION
With SQLINTERGRATION
Do While .EOF = False
sTemp = txtsqlmessage
MsgBox sTemp
'...
.MoveNext
Loop
End With
-
Sep 11th, 2006, 06:55 AM
#4
Frenzied Member
Re: is it possible to pass variables from a textbox in visual basic?
The textbox has a .Text property. Call that.
BTW, ! is not allowed in variable or control names.
What context does this apply to?
Where do the name and amount come from? A database?
-
Sep 11th, 2006, 07:03 AM
#5
Re: is it possible to pass variables from a textbox in visual basic?
How do the variables get into the textbox? What is your query for that? (I see what you have in Post #3, but that doesn't look like it is doing anything.)
-
Sep 11th, 2006, 07:07 AM
#6
Thread Starter
Addicted Member
Re: is it possible to pass variables from a textbox in visual basic?
What context does this apply to?
Where do the name and amount come from? A database?
name and amount are coming from a database.
This is what i am trying to achieve. a user types a custom message on a textbox where he has included the variables. My app then does a loop through the recordset a creates a customized message fro each record.
-
Sep 11th, 2006, 07:08 AM
#7
Re: is it possible to pass variables from a textbox in visual basic?
Ok. Then what is contained in txtSQL.Text?
-
Sep 11th, 2006, 07:10 AM
#8
PowerPoster
Re: is it possible to pass variables from a textbox in visual basic?
So the variables are taken from the database...put into a textbox...
Now I am guessing that what you want is for the text in text1 (for instance) which says "Hallo !name, your current balance is !amount. please pay this amount to avoid disconnection!!! Customer Service." to be changed to replace !amount and "!name" with the actual name and amount.
If so, try "text2 = replace(text1,"!name",txtName)" and "text2 = replace(text2,"!amount",txtAmount)
Edit: Hack, I am guessing it's "Hallo " & !Name & ", your current balance is " & !amount & ". please pay this amount to avoid disconnection!!! Customer Service."
Well, everyone else has been doing it :-)
Loading a file into memory QUICKLY - Using SendKeys - HyperLabel - A highly customisable label replacement - Using resource files/DLLs with VB - Adding GZip to your projects
Expect more to come in future
If I have helped you, RATE ME! :-)
I love helping noobs with their VB problems (probably because, as an amateur programmer, I am only slightly better at VB than them :-)) but if you SERIOUSLY want to get help for free from a community such as VBForums, you have to first have a grounding (basic knowledge) in VB6, otherwise you're way too much work to help...You've got to give a little if you want to get help from us, in other words!
And we DON'T do your homework. If your tutor doesn't teach you enough to help you make the project without his or her help, FIND A BETTER TUTOR or try reading books on programming! We are happy to help with minor things regarding the project, but you have to understand the rest of it if you want our help to be useful.
-
Sep 11th, 2006, 07:16 AM
#9
Thread Starter
Addicted Member
Re: is it possible to pass variables from a textbox in visual basic?
Hi Hack
How do the variables get into the textbox? What is your query for that? (I see what you have in Post #3, but that doesn't look like it is doing anything.)
a user will type them in with a customised message. the query is also input by the user since my app is able to connect to any database. the user types in a query and the results are then put in a datagrid.
a message is then typed on a textbox including the variables. its kind of a mail merge..
-
Sep 11th, 2006, 07:31 AM
#10
Thread Starter
Addicted Member
Re: is it possible to pass variables from a textbox in visual basic?
So the variables are taken from the database...put into a textbox...
the variables are not put into a text box. they are put into a datagrid and the user types the column heading preceeded by a ! to denote the variable. hope am not confusing you
-
Sep 11th, 2006, 07:35 AM
#11
PowerPoster
Re: is it possible to pass variables from a textbox in visual basic?
I think that *basically* the function you need is replace...I describe how to use it above, but it's as simple as replace=(STRING,FINDTHIS,REPLACEWITHTHIS)
So if you had debug.print replace("abcdefghijk","abc,"ABC") it would return "ABCdefghijk"...so it replaces "abc" with "ABC"...sound as simple as ABC to you now? :-)
Well, everyone else has been doing it :-)
Loading a file into memory QUICKLY - Using SendKeys - HyperLabel - A highly customisable label replacement - Using resource files/DLLs with VB - Adding GZip to your projects
Expect more to come in future
If I have helped you, RATE ME! :-)
I love helping noobs with their VB problems (probably because, as an amateur programmer, I am only slightly better at VB than them :-)) but if you SERIOUSLY want to get help for free from a community such as VBForums, you have to first have a grounding (basic knowledge) in VB6, otherwise you're way too much work to help...You've got to give a little if you want to get help from us, in other words!
And we DON'T do your homework. If your tutor doesn't teach you enough to help you make the project without his or her help, FIND A BETTER TUTOR or try reading books on programming! We are happy to help with minor things regarding the project, but you have to understand the rest of it if you want our help to be useful.
-
Sep 12th, 2006, 12:28 AM
#12
Re: is it possible to pass variables from a textbox in visual basic?
leaving it for the user to type the query in sounds like an error waiting to happen
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Sep 12th, 2006, 01:46 AM
#13
Thread Starter
Addicted Member
Re: is it possible to pass variables from a textbox in visual basic?
i only allow SELECT statements to be typed. Inserts Drops alters are disabled. n way only an admin will be using the system.
below is a screenshot of the app.
Screenshot
hope this will be more clearer on the predicament i am facing?
-
Sep 12th, 2006, 02:02 AM
#14
Fanatic Member
Re: is it possible to pass variables from a textbox in visual basic?
So you need to take a string message such as "Hello !name, your current balance is !amount", which you get from the user via a textbox, and replace the ![variable] parts with the value of the column with the same name in the datagrid, and do that for each row in the datagrid, creating many results?
The human brain cannot hold all of the knowledge that exists in this world, but it can hold pointers to that knowledge.
-
Sep 12th, 2006, 02:04 AM
#15
Thread Starter
Addicted Member
Re: is it possible to pass variables from a textbox in visual basic?
Thats exactly what i want to achieve. is it possible or is there a simpler way to do this.
-
Sep 12th, 2006, 02:19 AM
#16
Fanatic Member
Re: is it possible to pass variables from a textbox in visual basic?
Pseudo-code - since I haven't used VB6 in a while and I never used the DataGrid...
VB Code:
Dim strResult As String
for each row in the data grid
for each column in the row
replace "!" & column name in strResult with value from column
next
'do something with strResult which now has all the values from current row
next
The human brain cannot hold all of the knowledge that exists in this world, but it can hold pointers to that knowledge.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|