473,763 Members | 5,466 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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).strUse rID = "FredTran"
Accts(1).dblPas sWD = 2235
Accts(1).dblBal ance = 2010

'Method to request cash
Public Function requestCash(ByV al 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("Pleas e enter your " &
strType, _
strTitle, "")
If Len(Trim(strInp ut)) = 0 Then 'user pressed
cancel
Exit Function
ElseIf IsNumeric(strIn put) _
AndAlso strInput.IndexO f(".") = -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.Cri tical, strTitle)
End If
Loop Until IsNumeric(strIn put) AndAlso
strInput.IndexO f(".") = -1
Next
'OK, We have a USERID and PIN. Check to see if they exist
in array
intCtr = 0
Do Until (strUserID = CDbl(Accts(intC tr).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.Cri tical, "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.Cri tical, "Invalid PIN")
Else
'we have valid User ID and PIN
'check user's balance against request
If intAmount Accts(intCtr).d blBalance Then
MsgBox("You have insufficient funds to
complete the transaction. This transaction is cancelled.",
MsgBoxStyle.Cri tical, "INSUFFICIE NT 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.Cri tical,
"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.Cri tical, "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).d blBalance = _
Accts(intCtr).d blBalance - intAmount
Else
MsgBox("Amount requested can't be
delivered with existing bills.", MsgBoxStyle.Cri tical, "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 1195
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).strUse rID = "FredTran"
Accts(1).dblPas sWD = 2235
Accts(1).dblBal ance = 2010

'Method to request cash
Public Function requestCash(ByV al 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("Pleas e enter your " &
strType, _
strTitle, "")
If Len(Trim(strInp ut)) = 0 Then 'user pressed
cancel
Exit Function
ElseIf IsNumeric(strIn put) _
AndAlso strInput.IndexO f(".") = -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.Cri tical, strTitle)
End If
Loop Until IsNumeric(strIn put) AndAlso
strInput.IndexO f(".") = -1
Next
'OK, We have a USERID and PIN. Check to see if they exist
in array
intCtr = 0
Do Until (strUserID = CDbl(Accts(intC tr).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.Cri tical, "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.Cri tical, "Invalid PIN")
Else
'we have valid User ID and PIN
'check user's balance against request
If intAmount Accts(intCtr).d blBalance Then
MsgBox("You have insufficient funds to
complete the transaction. This transaction is cancelled.",
MsgBoxStyle.Cri tical, "INSUFFICIE NT 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.Cri tical,
"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.Cri tical, "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).d blBalance = _
Accts(intCtr).d blBalance - intAmount
Else
MsgBox("Amount requested can't be
delivered with existing bills.", MsgBoxStyle.Cri tical, "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
5655
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 at the bottom. Hope you can help me understand the "explicit" keyword and its usage. Specifically, Is "explicit" keyword only associated with constructor in C++? What's "implied conversion of types"?
7
3259
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 I couldn't find the exact rule in the C++ standard. And what if the classes have template parameters? It would be great if somebody could get me a rough hint where in the
16
5137
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. And K&R2 mentions "signed extension" everywhere. Reading some old clc posts, I've beginning to realize that these books are over-generalizing the topic. I am just wondering what the difference between the following pairs of terms are: 1)...
31
6648
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 variable becomes 364 and the other one becomes 365. Does anyone have any insight to what the problem is? Thanks in advance. Bjørn
11
7622
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 Test. I expected the same error from the following line, but it compiles fine. The double is silently truncated to an int and then fed in to the implicit conversion operator. Why does this happen? Is there any way that I can keep the implicit...
2
6868
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 static explicit System.IntPtr (long);
3
4457
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 calling the constructor 'MyString::MyString(const wchar_t *)' c:\SrNet\jury\JuryTest.h(21) : see declaration of 'MyString::MyString' The class "StringData" uses a, whatever you call it, operator const
0
2292
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 pages to a variety of formats. SII's service bureau has a reputation as being a least-cost provider that can offer a timely turnaround with 100% accuracy. Here are some of the formats SII has converted over the last 20 years:
0
1866
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 provides form data entry, data capture, HTML/SGML coding, image scanning, file conversion with low cost, high quality,99.98% accuracy and time bound. Data Conversion Services offer cost effective data conversion projects, Outsourcing Data...
21
2459
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 type is not a single identifier or keyword. Which one is correct? For example: unsigned long x = unsigned long(y); REH
0
9564
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9387
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10002
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9938
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9823
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7368
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6643
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
3917
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3528
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.