473,396 Members | 1,786 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

how can I fix this dbl to str conversion?

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

Mar 2 '07 #1
1 1184
Ron
My problem now is when I enter a userid it tells me userid I entered
is not valid.

On Mar 1, 8:59 pm, "Ron" <pts4...@yahoo.comwrote:
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

Mar 2 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Stub | last post by:
Docs says that "The compiler does not use an explicit constructor to implement an implied conversion of types. It's purpose is reserved explicitly for construction." I put up code of three cases...
7
by: Michael Lehn | last post by:
Hi, I have a question regarding the conversion of objects. When is the conversion done by the constructor and when by the operator. My feeling tells me that the constructor is preferred. But...
16
by: TTroy | last post by:
Hello, I'm relatively new to C and have gone through more than 4 books on it. None mentioned anything about integral promotion, arithmetic conversion, value preserving and unsigned preserving. ...
31
by: Bjørn Augestad | last post by:
Below is a program which converts a double to an integer in two different ways, giving me two different values for the int. The basic expression is 1.0 / (1.0 * 365.0) which should be 365, but one...
11
by: Steve Gough | last post by:
Could anyone please help me to understand what is happening here? The commented line produces an error, which is what I expected given that there is no conversion defined from type double to type...
2
by: Alex Sedow | last post by:
Why explicit conversion from SomeType* to IntPtr is not ambiguous (according to standart)? Example: // System.IntPtr class IntPtr { public static explicit System.IntPtr (int); public...
3
by: Steve Richter | last post by:
here is a warning I am getting in a C++ .NET compile: c:\SrNet\jury\JuryTest.cpp(55) : warning C4927: illegal conversion; more than one user-defined conversion has been implicitly applied while...
0
by: Lou Evart | last post by:
DOCUMENT CONVERSION SERVICES Softline International (SII) operates one of the industry's largest document and data conversion service bureaus. In the past year, SII converted over a million...
0
by: dataentryoffshore | last post by:
Get a Discount up to 60% on data entry, data capture, dataentry services, large volume data processing and data conversion services through offshore facilities in India. Offshore data entry also...
21
by: REH | last post by:
It it permissible to use the constructor style cast with primitives such as "unsigned long"? One of my compilers accepts this syntax, the other does not. The failing one chokes on the fact that the...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.