|
I have this program where I need to use multiple forms. Which hasn't been a problem. The program also needs to include a module in order to create a procedure to keep a running total of a number which is added in two different forms. It then needs to be displayed on the third form.
I am having problems making this number calculate on my display. Can anyone help?
Here is the module
'This is the Standard Module'
Option Strict On
Module Module1
Public Sub AddToOrder(ByVal intTotalSales As Integer, ByRef dblSubtotal As Double)
dblSubtotal = dblSubtotal + intTotalSales
End Sub
Public Function Taxes() As Double
Dim dbltaxRate As Double = 0.07
Dim dblSubtotal As Double
Return CDbl(dblSubtotal * dbltaxRate)
End Function
End Module
Here is the Display Form:
Option Strict On
Public Class frmDisplay
Private Sub btnClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClose.Click
'Closes the Bill
Me.Close()
End Sub
Private Sub frmDisplay_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'When the form is loaded, the date is going to appear as well as the total amount due for all coffee ordered'
Dim todayDate As Date = Today
txtBoxDate.Text = todayDate.ToString
'declare'
Dim decSalesTax As Decimal
Dim decSubtotal As Decimal
Dim dblSubtotal As Double
Dim intTotalSales As Integer
'calculate'
decSalesTax = CDec(Taxes())
decSubtotal = AddToOrder(intTotalSales, dblSubtotal)
'display'
txtBoxSubtotal.Text = decSubtotal.ToString
txtBoxTax.Text = decSalesTax.ToString
txtBoxTotal.Text = txtBoxSubtotal.Text + txtBoxTax.Text
End Sub
End Class
|
|
|
|
|
bphoopstar wrote: Public Sub AddToOrder(ByVal intTotalSales As Integer, ByRef dblSubtotal As Double)
This seems like such a waste of time to me. Why not just place delegates between the forms to communicate between them. Passing two values, one by ref, so they can be added together makes no sense at all.
bphoopstar wrote: Dim intTotalSales As Integer
'calculate'
decSalesTax = CDec(Taxes())
decSubtotal = AddToOrder(intTotalSales, dblSubtotal)
intTotalSales is obviously 0 at this point. Therefore, I don't see how this can do anything useful.
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
hello ! can you tell how to read data from store procedure in Dataset that have read from DATABASE by wizard ? i have a dataset that have bound data from SQL server by wizard. so this Dataset have all tables and views n store procedure, but i can't read data from it. speceilly i don kno how to get data from store procedure in that dataset . so please tell how to do ...?
hortpitou
|
|
|
|
|
What have you tried ?
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
i have a store procedure in sql server. and i created a dataset by wizard, so i can see in my dataset has Store procedure. but i don kno how to get data from that store procedure. so can u tell me how can i do ... ?
hortpitou
|
|
|
|
|
Pitou HORT wrote: and i created a dataset by wizard,
Perhaps if you wrote code, you'd have some idea of what you're doing. Why on earth do you need a wizard to create a dataset, if that wizard hasn't filled it from a data source ?
What have you tried ? Did you read any books ? Did you google for info and examples ? Where did this stored proc come from ? Surely you didn't write it ?
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
because of i have some reason have to use dataset by wizard. so can u show me or give me some guidline ? i have searched in google ready. but didn't find any idea.
my store procedure is get from sqlserver to dataset. please help me.....
hortpitou
|
|
|
|
|
Can I append the menustrip items from one form to another forms?
|
|
|
|
|
I suspect you'd need to clone them b/c the current ones are attached to a different form.
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
If you attach the exact same toolstrip items to another toolstrip they will vanish from the original toolstrip.
You will definately have to clone them.
If you have knowledge, let others light their candles at it.
Margaret Fuller (1810 - 1850)
www.JacksonSoft.co.uk
|
|
|
|
|
I'm doing a program that runs a math algorithm, and so should be very accurate. However, I'm facing this problem: 0.2+0.1<>0.3!
The code:
For i = 0 To 100 Step 0.1
Stop
Next
After the 4th stop i should be 0.3, but it's 0.30000000000000004!
Of course the difference is not big, but my program should be as accurate as possible.
I have no idea what can cause this.
Any explanation would be welcome.
The more you know the more you know how little you know, you know?
|
|
|
|
|
The real $M@ wrote: Any explanation would be welcome.
Short Version: decimal numbers <> binary numbers
Longer Version: Wikipedia page on floating point numbers
This is a common type of problem that is well known and documented all over the web. In your case, you may be able to iterate from 0 to 1000 instead and divide by 10 inside the loop.
|
|
|
|
|
Computers represent everything in binary, not decimal, and everything has to be crammed into 32, 64, or 128 bits (Depending on the precision).
In binary, the digits after the decimal correspond to 1/2, 1/4, 1/8, 1/16, etc., instead of 1/10, 1/100, 1/1000.
So representing 0.3 in binary is kind of like, say, representing 10/3 or 22/7 in decimal... You can write it out to a lot of digits, but you can't get it exactly right in that form. Normally, this approximation gets hidden, but when you do arithmetic, these errors get compounded until it starts to become visible.
There are thousands of articles on the web about this... Here's one: http://docs.sun.com/source/806-3568/ncg_goldberg.html[^]
|
|
|
|
|
Thanks for both answers. I understand now
The more you know the more you know how little you know, you know?
|
|
|
|
|
On the room form,include a combo box taht holds the room name. use check boxes to indicate if the room has a jacuzzi, private access, or fireplace. display the bed type and the room rates from the beds table
How to bind the checked property of a check box to a boolean data field
data looks like this
beds table
Doubles D 79.95 69.95
King K 105 95
Queen Q 95 85
rooms table
Forest K False False True
Garden K True True False
Library Q False True False
Ocean K False True True
Sun Room D False False False
so far I have this
'data tier
Imports System.Data
Public Class RoomsDataTier
' Module-level variables.
Private ARoomTableAdapter _
As CottagesDataSetTableAdapters.RoomsTableAdapter
Private ABedsTableAdapter _
As CottagesDataSetTableAdapters.BedsTableAdapter
Private ACottagesDataSet As CottagesDataSet
Public Sub New()
Try
' Instantiate the TableAdapters and DataSet.
ABedsTableAdapter = New _
CottagesDataSetTableAdapters.BedsTableAdapter()
ARoomTableAdapter = New _
CottagesDataSetTableAdapters.RoomsTableAdapter()
ACottagesDataSet = New CottagesDataSet
' Fill the DataSet.
ARoomTableAdapter.Fill(ACottagesDataSet.Rooms)
ABedsTableAdapter.Fill(ACottagesDataSet.Beds)
Catch ex As Exception
Throw ex
End Try
End Sub
Public Function GetDataSet() As CottagesDataSet
' Return the DataSet.
Return ACottagesDataSet
End Function
End Class
Imports System.Data
Public Class Rooms
' Module-level variables.
Private AroomsDataTier As RoomsDataTier
Private AcottagesDataSet As CottagesDataSet
Private RoomsBindingSource As BindingSource
Private BedsBindingSource As BindingSource
Private Sub StoreForm_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
' Set up the data for the combo box and text boxes.
Try
AroomsDataTier = New RoomsDataTier
AcottagesDataSet = AroomsDataTier.GetDataSet
' Set up stores binding source.
RoomsBindingSource = New BindingSource
With RoomsBindingSource
.DataSource = AcottagesDataSet
.DataMember = "Rooms"
.Sort = "Room"
End With
' Bind the form controls.
With RoomComboBox()
.DataSource = RoomsBindingSource
.DisplayMember = "Room"
.ValueMember = "BedCode"
.DataBindings.Add("text", RoomsBindingSource, _
"Room", False, DataSourceUpdateMode.Never)
.SelectedIndex = -1
End With
' Set up the binding source.
BedsBindingSource = New BindingSource
With BedsBindingSource
.DataSource = AcottagesDataSet
.DataMember = "Beds"
End With
Catch ex As Exception
MessageBox.Show("Error: " & ex.Message)
End Try
End Sub
Private Sub RoomNameComboBox_SelectionChangeCommitted( _
ByVal sender As Object, ByVal e As System.EventArgs) _
Handles RoomComboBox.SelectionChangeCommitted
' Retrieve the sales information for the grid.
Dim RoomsString As String
Static GridInitializedBoolean As Boolean
' Retrieve the ID of the selected store.
RoomsString = RoomComboBox.SelectedValue.ToString
RoomCheckBox1.DataBindings.Add("CheckState", RoomsBindingSource, "MyColumn", False, DataSourceUpdateMode.OnPropertyChanged, DBNull.Value)
' Initialize the grid's binding.
If Not GridInitializedBoolean Then
' Bind and format the grid.
DataGridView1.DataSource = BedsBindingSource
GridInitializedBoolean = True
End If
' Filter the grid's data.
BedsBindingSource.Filter = "BedCode = '" & RoomsString & "'"
End Sub
end class
I am getting a runtime error saying that
Cannot bind to the property or column MyColumn on the DataSource. Parameter name: dataMember
|
|
|
|
|
This is just a guess but I think you're trying to bind the checkbox to a field in your data source named "MyColumn". Does your data source (which I believe comes from your database) have a column named "MyColumn"? If not, change "MyColumn" to the name of the field you want to bind to.
|
|
|
|
|
I changed the column name and changed but now it is saying same thing
Cannot bind to the property or column Jacuzzi on the DataSource. Parameter name: dataMember
|
|
|
|
|
Again I'm just speculating but what is the data type of Jacuzzi in you database? It would need to be a boolean type and not a string.
|
|
|
|
|
It is a boolean type true , false
|
|
|
|
|
I changed my code little bit
Private Sub RoomNameComboBox_SelectionChangeCommitted( _
ByVal sender As Object, ByVal e As System.EventArgs) _
Handles RoomComboBox.SelectionChangeCommitted
' Retrieve the sales information for the grid.
Dim RoomsString As String
Dim RoomDataRow As DataRow
Dim BedDataRow As DataRow
AroomsDataTier = New RoomsDataTier
AcottagesDataSet = AroomsDataTier.GetDataSet
RoomDataRow = AcottagesDataSet.Rooms.FindByRoom(RoomComboBox.SelectedValue.ToString)
BedDataRow = RoomDataRow.GetParentRow("BedsToRooms")
' Retrieve the ID of the selected store.
RoomsString = RoomComboBox.SelectedValue.ToString
CheckBox1.Checked = CBool(RoomDataRow!Jacuzzi)
CheckBox2.Checked = CBool(RoomDataRow!Private_Access)
CheckBox3.Checked = CBool(RoomDataRow!Fireplace)
TextBox1.Text = CDbl(BedDataRow!WeekdayRate).ToString("c")
TextBox2.Text = CDbl(BedDataRow!WeekendRate).ToString("C")
End Sub
now the error was
Object reference not set to an instance of an object.
|
|
|
|
|
Then you need to step through the code and find which object isn't being set correctly. My guess is that AcottagesDataSet.Rooms.FindByRoom(RoomComboBox.SelectedValue.ToString) isn't returning anything.
|
|
|
|
|
Dear All,
I have designed a JPG file and want to use in splash screen in my vb.net project. I have set this image in form's background image property. In this JPG file, the blank space is filled with white background by default. But I dont need to show this white background in splash screen. Someone told me that there is a way to do this job by using transparency key. I tried alot by setting form's transparency key to white and also form's back color to white, but it doesn't work. Can anyone help me...
Thanks
Ovais
|
|
|
|
|
The transparency key likely wont work for your image as the white is made of of several different shades of many colors. You probably would be best to just remove the white background from the jpg.Add an Alpha Channel to your image and clear out the white, if you don't have (or know you have) a program to do this, here are some instructions for doing it in GIMP which is a free editor.
http://weisbeek.freewebhostx.com/gimp/[^]
|
|
|
|
|
I'm not sure I'm right but JPEGs don't support transparency therefore try converting it to a PNG or GIF image and set the transparent colour in the colour pallet of the image.
Then set the image file as the background of the splash form and set the splash form transparency to the back color of the form.
Steve Jowett
-------------------------
Real programmers don't comment their code. If it was hard to write, it should be hard to read.
|
|
|
|
|
The image itself must support transparency, as has been said, you will have to save your image as a png or similar that supports transparency then make sure the transparent parts of the image really are transparent.
After that set the form transparency key and backColor to the same colour. I usually use Fuschia as it is to vile a colour to be used for real and instantly shows up if you made a mistake.
For more info on splash screens try any of the many articles here on code project eg. Creating a Splash Screen that runs without a message pump[^].
If you have knowledge, let others light their candles at it.
Margaret Fuller (1810 - 1850)
www.JacksonSoft.co.uk
|
|
|
|