how can I fix this dbl to str conversion?

R

Ron

Hello all,

I had my code working using a number userid, then I chganged it to
string and thought I did everything right, well now this function
does not work. Anyone know what I am doing wrong?

And how can I fix it? So I am having a problem with struserid and my
array looks like this:
one element
Accts(1).strUserID = "FredTran"
Accts(1).dblPassWD = 2235
Accts(1).dblBalance = 2010

'Method to request cash
Public Function requestCash(ByVal intAmount As Integer) As
String
Dim intCtr, int20Required, int10Required, int5Required As
Integer
Dim strUserID As String
Dim dblPIN, dblBalance As Double
Dim strInput, strType, strTitle As String
Dim intOrigPt5, intOrigPt10, intOrigPt20, intOrigPtTotal
As Integer
'Grab snapshot of ATM balances before transaction starts
intOrigPt5 = pt5
intOrigPt10 = pt10
intOrigPt20 = pt20
intOrigPtTotal = ptTotal
For intCtr = 0 To 1
Do
Select Case intCtr
Case 0
strType = "User ID"
strTitle = "USERID ENTRY"
Case Else
strType = "PIN"
strTitle = "PIN ENTRY"
End Select
strInput = InputBox("Please enter your " &
strType, _
strTitle, "")
If Len(Trim(strInput)) = 0 Then 'user pressed
cancel
Exit Function
ElseIf IsNumeric(strInput) _
AndAlso strInput.IndexOf(".") = -1 Then 'input
is numeric and
does not contain a decimal pt
Select Case intCtr
Case 0
strUserID = CStr(CDbl(CStr(strInput)))
Case Else
dblPIN = CDbl(strInput)
End Select
Else
Select Case intCtr
Case 0
strType = "User ID"
strTitle = "INVALID USERID"
Case Else
strType = "PIN"
strTitle = "INVALID PIN"
End Select
MsgBox("You have entered an invalid" & strType
& ". Please re-enter.", MsgBoxStyle.Critical, strTitle)
End If
Loop Until IsNumeric(strInput) AndAlso
strInput.IndexOf(".") = -1
Next
'OK, We have a USERID and PIN. Check to see if they exist
in array
intCtr = 0
Do Until (strUserID = CDbl(Accts(intCtr).strUserID) Or _
intCtr > UBound(Accts) - 1)
intCtr += 1
Loop
If intCtr > UBound(Accts) - 1 Then
'Non-Existent User ID
MsgBox("You have entered a non-existent User ID. This
transaction is cancelled.", MsgBoxStyle.Critical, "Non-Existent User
ID")
Else
'Valid User ID. Now, check the PIN
If dblPIN <> Accts(intCtr).dblPassWD Then
'Incorrect PIN
MsgBox("You have entered an invalid PIN. This
transaction is cancelled.", MsgBoxStyle.Critical, "Invalid PIN")
Else
'we have valid User ID and PIN
'check user's balance against request
If intAmount > Accts(intCtr).dblBalance Then
MsgBox("You have insufficient funds to
complete the transaction. This transaction is cancelled.",
MsgBoxStyle.Critical, "INSUFFICIENT FUNDS")
Else
'check user's request and ensure it is
divisible by 5
If intAmount Mod 5 <> 0 Then
MsgBox("You have entered an invalid
amount. " & _
"Amount must be divisible by 5. Please "
& _
"Re-enter", MsgBoxStyle.Critical,
"IMPROPER REQUEST")
'check user's request against ATM balance
ElseIf intAmount > ptTotal Then
MsgBox("We're sorry. This ATM does NOT
have " & "sufficient funds to satisfy your request",
MsgBoxStyle.Critical, "ATM SHORT")
Else
'adjust ATM's total cash balance
ptTotal = ptTotal - intAmount
'For 20s, first determine the number of
20s needed
'to satisfy user's request
int20Required = intAmount \ 20
'Then check to see if ATM has enough 20s
to handle it
If int20Required <= pt20 Then
'adjust requested amount by VALUE of
20s
intAmount = intAmount - (int20Required
* 20)
'adjust ATM's supply of 20s
pt20 = pt20 - int20Required
Else
'ATM does NOT have enough 20s so use
all that are 'available and adjust
the requested amount by the
'VALUE of 20s used. Then, set ATM's
supply of 20s
'to zero.
intAmount = intAmount - (pt20 * 20)
pt20 = 0
End If
'For 10s, first determine the number of
10s needed
'to satisfy the remainder of user's
request
int10Required = intAmount \ 10
'Then check to see if ATM has enough 10s
to handle it
If int10Required <= pt10 Then
'adjust requested amount by VALUE of
10s
intAmount = intAmount - (int10Required
* 10)
'adjust ATM's supply of 10s
pt10 = pt10 - int10Required
Else
'ATM does NOT have enough 10s so use
all that are 'available and adjust
the requested amount by the
'VALUE of 10s used. Then, set ATM's
supply of 10s
'to zero.
intAmount = intAmount - (pt10 * 10)
pt10 = 0
End If
'For 5s, first determine the number of 5s
needed
'to satisfy the remainder of user's
request
int5Required = intAmount \ 5
'Then check to see if ATM has enough 5s to
handle it
If int5Required <= pt5 Then
'adjust requested amount by VALUE of
5s
intAmount = intAmount - (int5Required
* 5)
'adjust ATM's supply of 5s
pt5 = pt5 - int5Required
'adjust user's balance (accts array)
Accts(intCtr).dblBalance = _
Accts(intCtr).dblBalance - intAmount
Else
MsgBox("Amount requested can't be
delivered with existing bills.", MsgBoxStyle.Critical, "ATM
Denomination Shortage")
pt5 = intOrigPt5
pt10 = intOrigPt10
pt20 = intOrigPt20
ptTotal = intOrigPtTotal
End If
End If
End If
End If
End If
End Function
End Class
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top