TheSwamp
Code Red => VB(A) => Topic started by: JohnK on September 02, 2005, 11:48:58 AM
-
I made a simple helper procedure to help demonstrate my question. please see quotes.
Public Function MakeTen(X As Integer)
' make an int at least ten.
If X >= 10 Then
' how do I return the value?
End
Else
X = 1 + X
MakeTen (X)
End If
End Function
Sub MainProc()
' How do I ask for a value?
' (dialog box is fine but how do I convert the string to an int?)
' ie Userform1.TextBox1.text ...
MakeTen (...)
' now that I have an int at least ten how do I display it in a msgbox.
End Sub
-
Public Function Times10 ( Argument as Integer ) As Integer
Times10 = 10 * Argument
End Function
If the return type is a class then you have to use the set statement.
-
This is according to your comments. Or from what I understood at least
Public Function MakeTen(X As Integer) As Integer
' make an int at least ten.
If X >= 10 Then
MakeTen = X
Else
MakeTen = 10
End If
End Function
Sub MainProc()
Dim strValue As String
Dim i As Integer
strValue = InputBox("Please enter an Integer", "theswamp.org", 1)
i = MakeTen(CInt(strValue))
MsgBox i
End Sub
-
you will also need to handle it if they type something other than an integer.
Sub MainProc()
Dim strValue As String
Dim i As Integer
On Error GoTo YouBwokedIt
strValue = InputBox("Please enter an Integer", "theswamp.org", 1)
i = MakeTen(CInt(strValue))
MsgBox i
LeavingOnAJetTrain:
Exit Sub
YouBwokedIt:
Select Case Err.Number
Case 13
Err.Clear
strValue = InputBox("Hint: An Integer is a number" & vbCrLf & "Please enter an Integer", "theswamp.org", 1)
Resume
Case Else
MsgBox "Oh my god...It's full of stars."
GoTo LeavingOnAJetTrain
End Select
End Sub
Do you really want an integer? That would be whole numbers larger than -32,768 and smaller than 32,767 only. If you need numbers outside that range or decimals, you might want to go with doubles instead.
-
Bwaaa, great odyssey ref.
-
I feel it's improtant to always be as descriptive as possible with error control.. It keeps users from getting confused and makes debugging a lot easier.
-
Bob, your having way to much fun at work