Please help w/ VB question..
Results 1 to 8 of 8

Thread: Please help w/ VB question..

  1. #1

    Post Please help w/ VB question..

    Okay, I need assistance with a VB program.. Let's say in the most basic program we have to take the amount of an item and divide it by the price, to get the unit price..

    I need to take "16 Oz" from a textbox which would be the amount variable divide it by let's say "16" from the amount to get the individual price per unit.. Okay.. Easy enough... using the Var(txtAmount.text) code.. I can extract the "16" from the "16 Oz" and I get an even 1 as my output to the unit price.. But now I need to extract the "Oz" from the string to output "1 Oz" How would I do that? I've tried all different things, but I keep receiving errors. I was hoping some knowledgable individual could give me some ideas... Thank you.. Also.. If you could, please respond within the next 3 1/2 hours.. I have a deadline.. Thank you..


  2. #2
    Senior Member
    Join Date
    Jan 2002
    i can't tell if you're dealing with a database or not...sounds like you might be so i'll answer as if you were... shouldn't be mixing numbers and text strings...makes life too difficult...

    i'd keep qty = integer, unit/wt = string then you can do all your manipulation with out this issue...

    but if you're stuck with it...

    just assign the oz part of the string to a var and then concatenate that to the unit price cal var

    myvalue = varUnitPrice & " " & varUnitWt

    and if unit wt never can just

    myvalue = varUnitPrice & " oz."

    again...this is based on a guess that you're using vba and are working with a db...if not...hope it still applies or maybe point you rightly...
    I used to be With IT. But then they changed what IT was. Now what I'm with isn't IT, and what's IT seems scary and weird." - Abe Simpson

  3. #3
    Senior Member
    Join Date
    Oct 2001
    the same method should work in most programs with vb, to get specifics look in the vb help file or reference book under concatenate.

    If you give me the code, I could probably do it myself fairly quickly
    Preliminary operational tests were inconclusive (the dang thing blew up)

    \"Ask not what the kernel can do for you, ask what you can do for the kernel!\"

  4. #4
    The code looks something like this..

    Dim size As String
    Dim price As Single
    Dim unit As Single
    Dim weight As String

    Private Sub Label1_Click()

    End Sub

    Private Sub cmdCalc_Click()

    size = Val(txtSize.Text)
    price = txtPrice.Text
    weight = Str$(txtSize.Text)
    unit = price / size
    txtUnit.Text = unit & " " & weight

    /// Here I need to get it to print out.. The "Oz" part of the "17 Oz" without the "17" but I'm not sure if the language can differentiate between 1 and 7 as ASCII characters, or if it can actually eliminate the numbers from the string and throw in the "Oz"; I still receive an error from this.. I can't quite figure this one out.. I can get it to work fine.. But as an exercize.. I am trying this out.. I can't put in "txtUnit.Text = Unit & " Oz."" because if it were any other unit of measurement it would not work accurately.. If you can figure this out, that would be great.. I'll keep checking back.. Thank you.

    End Sub

  5. #5
    Join Date
    Oct 2001
    why not have Oz as a label?
    \"Not all humans are reasonably good.\" -John Locke

  6. #6
    Senior Member
    Join Date
    Jan 2002
    how about
    weight = right(varWholeString, 2)


    weight = right(varWholeString, 3)

    2 or 3 depending on whether you use oz. or jus oz (no <.>)

    in this ex the last 2 or 3 chars can be eval'ed whatever they are...
    I used to be With IT. But then they changed what IT was. Now what I'm with isn't IT, and what's IT seems scary and weird." - Abe Simpson

  7. #7
    AO French Antique News Whore
    Join Date
    Aug 2001


    If you have a text box that contain 16 OZ, you can use the code

    SDK as String
    SDK = Right(txtAmount.text, 2)
    ' SDK will = OZ

    This code will give you the last 2 caracters from the right. You can also write

    SDK = Left(txtAmount.text, 2)
    'SDK will = 16

    To get the 2 first caracters from the left and

    SDK = Mid(txtAmount.text, 2, 4)
    SDK will = ' OZ"

    The command MID will put the 4 caracters from the second caracters on in of your txtAmount.text in the variable SDK.
    -Simon \"SDK\"

  8. #8

    Thanks for the help.. =]


    SDK, your method worked perfectly!

    Zigar, thanks for your help, too!

    Kezil, you too!

    Mrln, I would if I could.. But let's say they entered mL instead of Oz.. I would be stuck with mL still.. But thank you for the help.


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts