|
One way to deal with this, and I repeat ONE way, is to create a class to hold the charging information and in your form_load event handler add an instance of this class to each of the RadioButtons .
Here is a very simple example of such a class:
Public Class ChargingInfo
Private bHours As Int32 'base hours
Private bRate As Double 'base rate
Private aRate As Double 'additional rate
Public Property BaseHours() As Int32
Get
Return Me.bHours
End Get
Set(ByVal value As Int32)
Me.bHours = value
End Set
End Property
Public Property BaseRate() As Double
Get
Return Me.bRate
End Get
Set(ByVal value As Double)
Me.bRate = value
End Set
End Property
Public Property AdditionalRate() As Double
Get
Return Me.aRate
End Get
Set(ByVal value As Double)
aRate = value
End Set
End Property
End Class
and the Form_Load handler:
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim ci As ChargingInfo = New ChargingInfo()
ci.BaseHours = 10
ci.BaseRate = 9.95
ci.AdditionalRate = 2.0
Me.radA.Tag = ci
ci = New ChargingInfo()
ci.BaseHours = 20
ci.BaseRate = 14.95
ci.AdditionalRate = 1
Me.radB.Tag = ci
ci = New ChargingInfo()
ci.BaseHours = 0
ci.BaseRate = 19.95
ci.AdditionalRate = 0
Me.radC.Tag = ci
End Sub
Then in your btnCalculate_Click event handler you first retrieve the ChargingInfo from the checked RadioButton and that can then be used throughout the calculation. (As an alternative you could handle the CheckedChanged event handler for the RadioButtons and set a form wide variable to the correct ChargingInfo ). Something like this:
Private Sub btnCalculate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalculate.Click
Dim cost As Double
Dim ci As ChargingInfo
Dim chargeableHours As Int32 = Math.Min(744, enteredHours)
If Me.radC.Checked Then
ci = CType(Me.radC.Tag, ChargingInfo)
ElseIf Me.radB.Checked Then
ci = CType(Me.radB.Tag, ChargingInfo)
Else
ci = CType(Me.radA.Tag, ChargingInfo)
End If
If ci.BaseHours = 0 Then
cost = chargeableHours * ci.BaseRate
Else
cost = Math.Min(ci.BaseHours, chargeableHours) * ci.BaseRate
chargeableHours = chargeableHours - ci.BaseHours
If chargeableHours > 0 Then
cost = cost + (chargeableHours * ci.AdditionalRate)
End If
End If
If Me.chboxNonProfit.Checked Then
cost = cost * 0.8
End If
Me.txtTotalCost.Text = cost.ToString()
End Sub
**NOTE** enteredHours is the number of hours actually used, you didn't say where that comes from.
Hope that this gives you some ideas.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
Henry - I've seen smaller article than that !
|
|
|
|
|
Mycroft Holmes wrote: Henry - I've seen smaller article than that
Yep. I sometimes get carried away.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
hi Guys...
do you know of any links that will teach me on how to create a simple gantt chart in vb.net.
or any free controls available for my project.
i have tried google and msdn but have not seen anything that would point me in the right direction.
i need this to create a simple sched program.
thanks
Anoop
|
|
|
|
|
Have you seen Gantt Chart / Event Calendar / Calendar Planner[^] from here on Code Project?
It is a web control, but it might give you some ideas on how to implement your own.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
Hi,
Thx, will check this out!
much appreciated!
|
|
|
|
|
This
Gantt Chart[^]
is excellent.
I don't speak Idiot - please talk slowly and clearly
I don't know what all the fuss is about with America getting it's first black president. Zimbabwe's had one for years and he's sh*t. - Percy Drake , Shrewsbury
Driven to the arms of Heineken by the wife
|
|
|
|
|
I made a console program that is used by a local carpet company. I am still new to VB.NET and dont know what is the correct syntax for passing variables between subroutines? I am using global variables right now and i know that it is not the best way to do things. So I have provided one of my subroutines below? How would I create variables byVal as an argument
Module CarpetCoInc
Dim dFeet, dWidth As Double 'store width and feet
Dim dCarPrice, dPadPrice, dLaborCost As Double 'store carpet price, pad price, and labor cost
Dim dCarpetCost As Double 'for cost display
Dim dPadCost As Double 'cost display
Dim dLabor As Double 'cost display
Dim dSubTotal As Double 'subtotal display
Dim dSTax As Double 'sales tax display
Dim dSqYrds As Double 'sq yards
Dim dGrandTotal As Double 'store grand total amount
'variables needed to create and output file
Dim fileName As String
Dim fileWriter As StreamWriter
Dim output As FileStream
Sub Main()
'this is the main subroutine for the entire program
Call InputVals() 'call subroutine
Call Display() 'call subroutine
Call BidFile() 'call subroutine
Console.Read() 'pause screen
End Sub
Public Sub InputVals()
'this subroutine will be used to display and obtain data from user
'display data
Console.WriteLine("Please enter Length of room in Feet: ")
dFeet = Console.ReadLine 'get data and assign it to variable
'dF = Console.ReadLine
Console.WriteLine()
Console.WriteLine("Please enter Width of room in Feet: ")
dWidth = Console.ReadLine 'get data and assign it to variable
Console.WriteLine()
Console.WriteLine("Please enter Price per Yard of carpet: ")
dCarPrice = Console.ReadLine 'get data and assign it to variable
Console.WriteLine()
Console.WriteLine("Please enter Price per yard of pad: ")
dPadPrice = Console.ReadLine 'get data and assign it to variable
Console.WriteLine()
Console.WriteLine("Please enter Price per yard of Labor: ")
dLaborCost = Console.ReadLine 'get data and assign it to variable
Console.WriteLine()
End Sub
|
|
|
|
|
hi,
declare your variables in the subroutines.
in your case this should be enougth..
sub main()
dim tmp as string
dim dLaborCost as double
' read the line
tmp = GetPrice()
' cast the value of tmp to an double
dLaborCost = CDbl(tmp)
'......
end sub
private function GetPrice() as string
GetPrice = Console.ReadLine
end function
|
|
|
|
|
ok so basically i need to use byVal or byRef to pass my
data between subroutines.
i just dnt know th correct syntax
so i have
module mod1
sub main()
'where i call all my subroutines
*****I DNT KNOW HOW TO THEN CALL MY SUBROUTINE
call getData(dFeet)
???????
end sub
********THIS IS WHAT I DONT KNOW IF IT IS CORRECT
sub getData(byVal dim dFeet as double)
??????????
console.writeline("eneter feet: ")
dFeet = console.readline
'and so on for other data being asked to be entered
end sub
|
|
|
|
|
I suggest you buy and study a book on VB.NET; you can't get familiar with a programming language by asking hundreds of questions one by one. Choose a book you like, study it, and in one week's time you will be a lot wiser.
Luc Pattyn
I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages
Local announcement (Antwerp region): Lange Wapper? Neen!
|
|
|
|
|
Try this:
Module Module1
Public Sub DoSomething(ByVal x As Integer, ByRef y As Double)
x += 5
y += 5
End Sub
Sub Main()
Dim num As Integer = 5
Dim anum As Double = 20.5
Console.WriteLine("Before Method Call:")
Console.WriteLine("Num = {0}", num.ToString)
Console.WriteLine("Anum = {0}", anum.ToString)
DoSomething(num, anum)
Console.WriteLine("After Method Call:")
Console.WriteLine("Num (After ByVal) = {0}", num.ToString)
Console.WriteLine("Anum (After ByRef) = {0}", anum.ToString)
Console.Read()
End Sub
End Module
What happens?
This is what ByVal and ByRef do.
I don't speak Idiot - please talk slowly and clearly
I don't know what all the fuss is about with America getting it's first black president. Zimbabwe's had one for years and he's sh*t. - Percy Drake , Shrewsbury
Driven to the arms of Heineken by the wife
|
|
|
|
|
I am trying to filter a database with column name as "JoiningDate" with the following command:
cmd = New SqlCommand("SELECT * FROM student_details WHERE [JoiningDate] <= '" + fordate + "'", con)
Where,
Date format in my database is in "dd/MM/yyyy"
and
"fordate" is "10/01/2009", which is As string
Now while filtering, I am getting number of rows different than the exact ones ( This I know).
e.g. for the above filter of "joiningDate" less than "10/01/2009", I found that some other dates like
01/10/2009 is also get counted while filtering. I think there is something wrong in my implementation of
filtering.
I am pasting my code here :
Dim datetime_from As Date, fordate As String
' read the date from datetimepicker control "DateTimefrom"
datetime_from = DateTimefrom.Value.ToShortDateString
fordate = datetime_from.ToString("dd/MM/yyyy")
' then filtering by
cmd = New SqlCommand("SELECT * FROM student_details WHERE [JoiningDate] <= '" + fordate + "'", con)
Can Someone help me with a piece of code?
Thanks
R.S
|
|
|
|
|
Why are you storing dates as strings in database? Now, you will need to perform conversions in order to calculate the dates lesser than selected dates.
It's not necessary to be so stupid, either, but people manage it. - Christian Graus, 2009 AD
|
|
|
|
|
Can You please tell me how to do this?
|
|
|
|
|
jeshra279 wrote: Can You please tell me how to do this?
Store dates as dates not as strings. You are comparing character strings not dates, which means the results will not be what you expect. Take a look at the documentation with particular reference to date values, rather than date formats.
|
|
|
|
|
Can You or Someone Please provide me a line of code for this? I am stuck at this point.
|
|
|
|
|
You really should not do it this way. If you have a DateTime datatype, use it. Don't you think so?
jeshra279 wrote: Please provide me a line of code for this?
It cannot be done in a line of code with current approach.
Still if you want to stick to this way, then since the values in your database are as strings, then break up the date, month and year part into seprate integers. Then start with checking that if the year is less than selected dates year. If the year is same, check for month and if month is same check for date. Then you can filter out the records.
Don't you think this is bit insane way of comparing dates?
PS: There can be a decent way than what I have told. But anyways, IMHO if you use strings to store dates, you are wrong no matter how you comapre them.
It's not necessary to be so stupid, either, but people manage it. - Christian Graus, 2009 AD
|
|
|
|
|
when you have a number (say 123) you store it in a numeric field, not as a "123" string, right?
when you have a date, a time, a datetime, you store it in a field of the corresponding type, and NOT as a string; doing it properly avoids all confusion about date formats and regional settings; and it saves CPU cycles.
If your database table has a date field that is currently a string, and you want it to become a date, then this should do it:
- add a new field, with a new name;
- issue an SQL command to populate the new field based on your interpretation of the existing field;
- adapt your code base to use the new field, and no longer use the old one;
- delete the old field;
- optionally rename the new field in the database table and in your code.
That is a one time effort saving you all the trouble you would otherwise have later when your app grows, and/or when your app gets used by more people in more countries.
Luc Pattyn
I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages
Local announcement (Antwerp region): Lange Wapper? Neen!
|
|
|
|
|
Hey all. On a new project im working on, which is about learning different areas in visual basic. One area i havnt covered much is writing to files and retrieving data from a file.
The program includes a update script, which justs checks online reading a .txt file to see if the version is newer, if so it downloads it. I would like to record when the user last press 'checkForUpdates' button. Take the timestamp and write it into a xml file. Then using a simple label to read and display the value inside the xml file.
I have been trying a few ways, just using timestamps i got lost.
Any help would be great,
Malcom
|
|
|
|
|
If you can show the code you have tried and explain the exact problem, it would be easier to help.
It's not necessary to be so stupid, either, but people manage it. - Christian Graus, 2009 AD
|
|
|
|
|
Oki sorry, i asked wrong, i have tried some ways but i can't get it to work.
Im not asking for the answer, that be wrong. I am learning it afterall.
I just need say a boost. Just a quick example of generating a timestamp then i can work it from there. I did some googling and believe i can easly use xml file just need to mess around abit more.
Sorry for the bother,
Malcom
|
|
|
|
|
DateTime.Now will give you the current time. And then, you can look into the classes in System.Xml namespace to write that to your XML file.
It's not necessary to be so stupid, either, but people manage it. - Christian Graus, 2009 AD
|
|
|
|
|
hi, here i have some code for you.
System.Xml.XmlTextWriter xtw = new System.Xml.XmlTextWriter("C:\\timestamp.xml",System.Text.Encoding.UTF8);
xtw.Formatting == Formatting.Indented;
xtw.Indentation = 4;
xtw.WriteStartDocument();
xtw.WriteStartElement("TimeStamp");
xtw.WriteString(DateTime.Now.ToOADate());
xtw.WriteEndElement();
xtw.WriteStartElement("TimeStampAttribute");
xtw.WriteAttributeString("DateTime",DateTime.Now.ToOADate())
xtw.WriteEndElement();
xtw.WriteEndDocument();
xtw.Close();
|
|
|
|
|
Thank you both. I tried your hints and i got somewhere. Just was hitting a wall. The time was coming out as 00:00:00. To the last replier before me, thanks for the code, really gave me a better idea of what i needed. Thanks
|
|
|
|