RWayneH
asked on
Changing a variable value
I am using an inputbox to set a variable:
strLineItem = InputBox("Enter a valid line item for this sales order number") 'Inputbox text
I would like to set another variable based on this input and call it: strLineItemPlus100
This variable is going to be the strLineItem + 100 but called strLineItemPlus100
Two things. One how would I make sure that strLineItem is an increment of one hundred. Two how would I set the new value strLineItemPlus100? so I can use that number later in the procedure?
Please advise and thanks.
strLineItem = InputBox("Enter a valid line item for this sales order number") 'Inputbox text
I would like to set another variable based on this input and call it: strLineItemPlus100
This variable is going to be the strLineItem + 100 but called strLineItemPlus100
Two things. One how would I make sure that strLineItem is an increment of one hundred. Two how would I set the new value strLineItemPlus100? so I can use that number later in the procedure?
Please advise and thanks.
And if, say, strLineItem is 123.45 and you want it to be 100, then do this.
strLineItem = Int(strLineItem - strLineItem Mod 100)
strLineItem = Int(strLineItem - strLineItem Mod 100)
ASKER
And how do I make sure that strLineItem gets a value that is an increments of 100?
So if strLineItem is 500, that makes strLineItemPlus100 = to 600
What does the Dim of strLineItemPlus100 As Double mean. The Double is throwing me off.
So if strLineItem is 500, that makes strLineItemPlus100 = to 600
What does the Dim of strLineItemPlus100 As Double mean. The Double is throwing me off.
"Double" is a type of variable just like "String" except that Double is a numeric type.
Does this help?
Does this help?
Dim strLineItemPlus100 As Double
Dim strLineItem As String
' Set up the data for this example so that strLineItem has a value
strLineItem = 555.45
' This makes strLineItem = 500
strLineItem = Int(strLineItem - strLineItem Mod 100)
strLineItemPlus100 = strLineItem + 100
Yep; dimensioning a variable with "str" as the prefix as a Double-precision variable is a little confusing.
Maybe:
However, it sounds like you want to assign a variable to the next highest multiple of 100 after the value inputted (strLineItem). In this case:
Regards,
-Glenn
Maybe:
Dim dblLineItemPlus100 as Double
makes a little more sense.However, it sounds like you want to assign a variable to the next highest multiple of 100 after the value inputted (strLineItem). In this case:
Sub assign_next()
Dim strLineItem As String
Dim intLineItemPlus100 As Integer
strLineItem = InputBox("Enter a valid line item for this sales order number") 'Inputbox text
intLineItemPlus100 = WorksheetFunction.Round(Val(strLineItem), -2) + 100
End Sub
Regards,
-Glenn
ASKER
How do I make sure that the strLineItem is a multiple of 100? It has to be something that ends in 00
Like 500, 10600, 50000,..... It need it to validate that before we start the procedure that it is a multiple of 100
so the above results for strLineItemPlus100 would be 600, 10700 and 50100. Depending on what is loaded in the InputBox.
Like 500, 10600, 50000,..... It need it to validate that before we start the procedure that it is a multiple of 100
so the above results for strLineItemPlus100 would be 600, 10700 and 50100. Depending on what is loaded in the InputBox.
If you need BOTH of the variables to be multiples of 100 - with the second one being 100 greater than the first, then try this code:
Regards,
-Glenn
Dim strLineItem As String
Dim intLineItemPlus100 As Integer
strLineItem = InputBox("Enter a valid line item for this sales order number") 'Inputbox text
strLineItem = WorksheetFunction.Round(Val(strLineItem),-2)
intLineItemPlus100 = strLineItem + 100
Regards,
-Glenn
ASKER
Line 5 looks like it is rounding it... is there a way not to use rounding at all. It has to be exact. A multiple of 100. If it is not I need it to fail and try again on the inputbox. Or will what you have work? If 115 is entered, fail If 165 entered fail.. It must be 100, 200, 300 etc. It is critical for further use later in the procedure.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Works GREAT!! Thanks for the help.
strLineItemPlus100 = strLineItem + 100