Results 1 to 16 of 16

Thread: is it possible to pass variables from a textbox in visual basic?

  1. #1

    Thread Starter
    Addicted Member Paradox's Avatar
    Join Date
    Sep 2004
    Location
    Nairobi
    Posts
    189

    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.
    Peny wise pound Foolish

  2. #2
    PowerPoster
    Join Date
    May 2006
    Location
    Location, location!
    Posts
    2,673

    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.

  3. #3

    Thread Starter
    Addicted Member Paradox's Avatar
    Join Date
    Sep 2004
    Location
    Nairobi
    Posts
    189

    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:
    1. Set SQLINTERGRATION = New ADODB.Recordset
    2.     Dim sTemp As String
    3.    
    4.     If txtsql.Text = "" Then
    5.         MsgBox "Please specify the sql string to be executed", vbInformation, "Error"
    6.         Exit Sub
    7.     End If
    8.    
    9.     SQLINTERGRATION.Open "" & txtsql.Text & "", gConnection, adOpenDynamic, adLockOptimistic
    10.     Set DGINtergartion.DataSource = SQLINTERGRATION
    11.     With SQLINTERGRATION
    12.         Do While .EOF = False
    13.             sTemp = txtsqlmessage
    14.             MsgBox sTemp
    15.         '...
    16.           .MoveNext
    17.         Loop
    18.     End With

  4. #4
    Frenzied Member
    Join Date
    Oct 2003
    Posts
    1,301

    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?

  5. #5
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    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.)

  6. #6

    Thread Starter
    Addicted Member Paradox's Avatar
    Join Date
    Sep 2004
    Location
    Nairobi
    Posts
    189

    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.
    Peny wise pound Foolish

  7. #7
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: is it possible to pass variables from a textbox in visual basic?

    Ok. Then what is contained in txtSQL.Text?

  8. #8
    PowerPoster
    Join Date
    May 2006
    Location
    Location, location!
    Posts
    2,673

    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.

  9. #9

    Thread Starter
    Addicted Member Paradox's Avatar
    Join Date
    Sep 2004
    Location
    Nairobi
    Posts
    189

    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..
    Peny wise pound Foolish

  10. #10

    Thread Starter
    Addicted Member Paradox's Avatar
    Join Date
    Sep 2004
    Location
    Nairobi
    Posts
    189

    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

  11. #11
    PowerPoster
    Join Date
    May 2006
    Location
    Location, location!
    Posts
    2,673

    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.

  12. #12
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    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

  13. #13

    Thread Starter
    Addicted Member Paradox's Avatar
    Join Date
    Sep 2004
    Location
    Nairobi
    Posts
    189

    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?
    Peny wise pound Foolish

  14. #14
    Fanatic Member
    Join Date
    May 2001
    Posts
    837

    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.

  15. #15

    Thread Starter
    Addicted Member Paradox's Avatar
    Join Date
    Sep 2004
    Location
    Nairobi
    Posts
    189

    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.
    Peny wise pound Foolish

  16. #16
    Fanatic Member
    Join Date
    May 2001
    Posts
    837

    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:
    1. Dim strResult As String
    2. for each row in the data grid
    3.     for each column in the row
    4.         replace "!" & column name in strResult with value from column
    5.     next
    6.     'do something with strResult which now has all the values from current row
    7. 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
  •  



Click Here to Expand Forum to Full Width