# 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?

###### Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Older than dirtCommented:
Dim strLineItemPlus100 As Double
strLineItemPlus100 =  strLineItem + 100
0
Older than dirtCommented:
And if, say, strLineItem is 123.45 and you want it to be 100, then do this.

strLineItem = Int(strLineItem - strLineItem Mod 100)
0
Author Commented:
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.
0
Older than dirtCommented:
"Double" is a type of variable just like "String" except that Double is a numeric type.

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
``````
0
Excel VBA DeveloperCommented:
Yep; dimensioning a variable with "str" as the prefix as a Double-precision variable is a little confusing.
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
0
Author Commented:
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.
0
Excel VBA DeveloperCommented:
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:

``````    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
0
Author Commented:
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.
0
Excel VBA DeveloperCommented:
RWayneH,
The code I provided forces whatever value is entered to be rounded to the nearest 100.  Enter 115, you get 100.  Enter 165, you get 200.  And intLineItemPlus100 is automatically 100 more.

If you want to force the user to enter a value rounded to the 100's place then try this instead:
``````Option Explicit
Sub rounder()
Dim intLineItem As String
Dim intLineItemPlus100 As Integer
Dim doit As Integer

InputLineItem:
intLineItem = InputBox("Enter a valid line item for this sales order number") 'Inputbox text
If intLineItem = "" Then Exit Sub
On Error GoTo QuitIt
If intLineItem <> WorksheetFunction.Round(Val(intLineItem), -2) Then
doit = MsgBox("Please enter a value rounded to the nearest one hundred (100).", vbCritical + vbOKCancel, "Invalid Entry")
If doit = vbCancel Then
Exit Sub
Else
GoTo InputLineItem
End If
End If
intLineItemPlus100 = intLineItem + 100

'Test results:
MsgBox "intLineItem: " & intLineItem & vbLf & _
"intLineItemPlus100: " & intLineItemPlus100
QuitIt:
End Sub
``````

-Glenn
0

Experts Exchange Solution brought to you by