Results 1 to 11 of 11

Thread: textboxes (NEWBIE question)

  1. #1

    Thread Starter
    Member
    Join Date
    Jul 2004
    Location
    56 miles W. O'Venus
    Posts
    55

    Unhappy textboxes (NEWBIE question)

    OK, I am an ANSI-C type programmer trying to create a simmple VB.net App. I have several text boxes where the user enters certain numbers. I need to take those entries and produce a result in another text box. To test how to do this, I have a simple equation in code and am trying to place the result in a textbox, with no success. I would appreciate any steering in the right direction.

    Richard

  2. #2
    Frenzied Member Mike Hildner's Avatar
    Join Date
    Jul 2002
    Location
    Des Moines, NM
    Posts
    1,690
    Not sure how much you know about vb, but if your text box is named, say myTextBox, you set the text property - e.g. myTextBox.Text = "Hello".

    If you're adding numbers, you may need to do some error checking to make sure the user did not type in letters.

    Can you post some code to point out where you're having troubles? Any exceptions being raised?

    Mike

  3. #3

    Thread Starter
    Member
    Join Date
    Jul 2004
    Location
    56 miles W. O'Venus
    Posts
    55
    Basically I need to take the numbers from the other text boxes and, after calculating an equation, put the result in another text box. So myTextBox.Text = "Hello" becomes myTextBox.Text = Result where Result is the equation answer. Of course I have tried this and it does not work. The result does not have to be in a text box, perhaps that is my problem.

    Richard

  4. #4
    Frenzied Member Mike Hildner's Avatar
    Join Date
    Jul 2002
    Location
    Des Moines, NM
    Posts
    1,690
    Post some code, so we can see why it doesn't work. Probably something simple, but one can guess forever.

  5. #5

    Thread Starter
    Member
    Join Date
    Jul 2004
    Location
    56 miles W. O'Venus
    Posts
    55
    Mike,
    I got it to work. I appreciate the help. I think I need to learn (suffer) more before I waste people time on this forum. I will be back when I have a more interesting problem. Way too early to display my code!

    One question I still have, although I have the text box outputing the answer, it seems like the text box is an input point. What is a better way to display the answer? e.g as plain text in/on the form.

    Richard

  6. #6
    Frenzied Member Mike Hildner's Avatar
    Join Date
    Jul 2002
    Location
    Des Moines, NM
    Posts
    1,690
    I guess that would be a Label control. It also has a Text property. Sometimes can be useful to set the AutoSize property to true also, so it auto-expands to fit your text.

  7. #7
    PowerPoster
    Join Date
    Dec 2003
    Location
    Bristol, England (but heart is in Virginia)
    Posts
    2,949
    Hi,

    You could also use a messagebox.show to display the result in a manner which demands attention.
    Taxes
    The more I learn about VB.NET the more I like dBaseIII Plus

    The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.

  8. #8

    Thread Starter
    Member
    Join Date
    Jul 2004
    Location
    56 miles W. O'Venus
    Posts
    55

    Output as Plain Text?

    OK I have had some sucess with code like:

    Fcco.Text = Val(Fosc.Text) * Val(M.Text) * Val(P.Text) * 2

    This places the result in the Fcco textbox. Since Fcco IS a textbox, the user could plug values in there which is not what I want since it is only an output. Anyway to have the result show up as plain text?


    Richard

  9. #9

    Thread Starter
    Member
    Join Date
    Jul 2004
    Location
    56 miles W. O'Venus
    Posts
    55
    OK, I have some plain text output using label:

    test1.Text = Str$(A)

    Richard

  10. #10
    PowerPoster
    Join Date
    Dec 2003
    Location
    Bristol, England (but heart is in Virginia)
    Posts
    2,949

    Re: Output as Plain Text?

    Originally posted by richas
    OK I have had some sucess with code like:

    Fcco.Text = Val(Fosc.Text) * Val(M.Text) * Val(P.Text) * 2

    This places the result in the Fcco textbox. Since Fcco IS a textbox, the user could plug values in there which is not what I want since it is only an output. Anyway to have the result show up as plain text?


    Richard
    In VB6 textboxes were of the variant type. In VB.NET they are solely strings. Therefore

    VB Code:
    1. Fcco.Text = Cstr(Val(Fosc.Text) * Val(M.Text) * Val(P.Text) * 2)

    There are other ways to convert to strings but that is the easiest.
    Taxes
    The more I learn about VB.NET the more I like dBaseIII Plus

    The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.

  11. #11
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170
    This is all very good and nice but I'd also suggest that you use a naming convention for your variables and controls. For example, naming a textbox as "M" won't be very helpful later on when you're asking someone else for help, or when you come back to your code later on.

    I'd name a textbox as txtM instead, integers as intSomething and strings as strFrog.

    HTH

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