This is the question I'm having difficulty figuring out. I'm unable to get splash screens to show up on my previous two questions I was able to complete the coding and design, but this one is throwing me for a loop.
This is what I have so far
Public Sub New()
InitializeComponent()
label2.Visible = False
label3.Visible = False
label4.Visible = False
comboBox1.Items.Add("Uber")
comboBox1.Items.Add("Subway")
comboBox1.Items.Add("Bus")
End Sub
Private Sub comboBox1_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs)
If comboBox1.SelectedIndex = 0 Then
label2.Visible = True
label3.Visible = True
label4.Visible = True
End If
If comboBox1.SelectedIndex = 1 Then
label2.Visible = True
label3.Visible = True
label4.Visible = False
End If
If comboBox1.SelectedIndex = 2 Then
label2.Visible = True
label3.Visible = True
label4.Visible = False
End If
End Sub
Related
I am done with designing the windows form::
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
ComboBox2.Visible = False
Label2.Visible = False
ComboBox3.Visible = False
Label3.Visible = False
ComboBox4.Visible = False
Label4.Visible = False
ComboBox5.Visible = False
Label5.Visible = False
DateTimePicker1.Visible = False
End Sub
Private Sub ComboBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox1.SelectedIndexChanged
If (ComboBox1.Text = "BY-ELECTION") Then
ComboBox2.Visible = True
Label2.Visible = True
DateTimePicker1.Visible = False
ElseIf (ComboBox1.Text = "GENERAL ELECTION") Then
ComboBox2.Visible = False
Label2.Visible = False
ComboBox3.Visible = False
Label3.Visible = False
ComboBox4.Visible = False
Label4.Visible = False
ComboBox5.Visible = False
Label5.Visible = False
DateTimePicker1.Visible = True
End If
End Sub
Private Sub ComboBox4_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox4.SelectedIndexChanged
If ComboBox4.SelectedValue = "" And ComboBox2.Text = "MP" Then
DateTimePicker1.Visible = True
End If
If (ComboBox4.Text = "MVITA") And ComboBox2.Text = "MCA" Then
Label5.Visible = True
ComboBox5.Visible = True
ComboBox5.Items.Clear()
ComboBox5.Items.Add("MAJENGO")
ComboBox5.Items.Add("MAKADARA")
ComboBox5.Items.Add("SHIMANZI")
ComboBox5.Items.Add("TONONOKA")
ComboBox5.Items.Add("TUDOR")
DateTimePicker1.Visible = False
End If
End Sub
Private Sub ComboBox3_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox3.SelectedIndexChanged
If (ComboBox3.Text = "MOMBASA") And ComboBox2.Text = "MP" Or (ComboBox3.Text = "MOMBASA") And ComboBox2.Text = "MCA" Then
Label4.Visible = True
ComboBox4.Visible = True
ComboBox4.Items.Clear()
ComboBox4.Items.Add("CHANGAMWE")
ComboBox4.Items.Add("JOMVU")
ComboBox4.Items.Add("KISAUNI")
ComboBox4.Items.Add("LIKONI")
ComboBox4.Items.Add("MVITA")
ComboBox4.Items.Add("NYALI")
End If
End Sub
Private Sub ComboBox2_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox2.SelectedIndexChanged
If ComboBox2.Text = "GOVERNORSHIP" Or ComboBox2.Text = "SENATOR" Then
Label3.Visible = True
ComboBox3.Visible = True
Label5.Visible = False
ComboBox5.Visible = False
DateTimePicker1.Visible = True
ComboBox4.Visible = False
Label4.Visible = False
ElseIf ComboBox2.Text = "MP" Or ComboBox2.Text = "MCA" Then
Label3.Visible = True
ComboBox3.Visible = True
DateTimePicker1.Visible = False
Label6.Visible = False
ComboBox4.Visible = False
Label4.Visible = False
ComboBox5.Visible = False
Label5.Visible = False
End If
End Sub
Private Sub ComboBox5_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox5.SelectedIndexChanged
Label6.Visible = True
DateTimePicker1.Visible = True
End Sub
and i am stuck at the command button.
My windows form has 5 combobox with items assigned to them but in this illustration i am going to use one item for example:
Combobox2 has item MCA
Combobox3(labeled COUNTY) has item MOMBASA
Combobox4(labeled CONSTITUENCY) has item MVITA
Combobox5(labeled WARD) has item SHIMANZI
I want if i select item MCA in combobox2 and click the button GENERATE a table:
will be created and saved in the path C:\Users\Administrator\Documents\ and populated in the following format
cell A2 = item selected in combobox3
cell B2= item selected in combobox4
cell C2=item selected in combobox5
cell H2 to be populated with random input be based on gender(male/female) and letters(ABCD only) in that order. ie cell H2= MALE,D
You can refer to the following code to generate DataTable.
Dim dt As DataTable = New DataTable
dt.Columns.Add("COUNTY")
dt.Columns.Add("CONSTITUENCY")
dt.Columns.Add("WARD")
dt.Rows.Add(ComboBox3.SelectedItem.ToString, ComboBox4.SelectedItem.ToString, ComboBox5.SelectedItem.ToString)
Then use the following code to export the data table to Excel:
Dim excelFilePath As String = "excel path"
Dim excelApp = New Excel.Application()
excelApp.Workbooks.Add()
Dim workSheet As Excel._Worksheet = excelApp.ActiveSheet
For i = 0 To dt.Columns.Count - 1
workSheet.Cells(1, i + 1) = dt.Columns(i).ColumnName
Next
For i = 0 To dt.Rows.Count - 1
For j = 0 To dt.Columns.Count - 1
workSheet.Cells(i + 2, j + 1) = dt.Rows(i)(j)
Next
Next
If Not String.IsNullOrEmpty(excelFilePath) Then
Try
workSheet.SaveAs(excelFilePath)
excelApp.Quit()
MessageBox.Show("Excel file saved!")
Catch ex As Exception
Throw New Exception("ExportToExcel: Excel file could not be saved! Check filepath." & vbLf & ex.Message)
End Try
End If
Result of the test looks like:
I'm working on this assignment where I need to have an array inside of a structure. The array consists of imported values from a text file:
2,3
3,4
4,4
5,5
5,4
6,3
3,6
9,9
10,10
1,5
2,5
3,5
1,4
2,4
3,4
4,4
I'm getting these errors:
Severity Code Description Project File Line Suppression State
Error BC30456 'real' is not a member of 'Form1.complexNumber()'. WindowsApplication3 e:\users\gabe\documents\visual studio 2015\Projects\Lab7_Gabriel_Carnes\WindowsApplication3\Form1.vb 68 Active
Severity Code Description Project File Line Suppression State
Error BC30311 Value of type 'Form1.complexNumber' cannot be converted to 'String'. WindowsApplication3 e:\users\gabe\documents\visual studio 2015\Projects\Lab7_Gabriel_Carnes\WindowsApplication3\Form1.vb 69 Active
I've tried moving the structure to be within a method instead of at form level but it then gives an error about not being able to be within a method.
Code:
Public Class Form1
Dim Real1, Real2, Imag1, Imag2 As Double
Dim Answer As String
Private Structure complexNumber
Public real As String
Public imag As String
End Structure
' Dim strValues() As fileInport =
' IO.File.ReadAllLines("Input.txt")
Dim Values(15) As complexNumber
Dim ValuesString As String
Dim line, data() As String
Dim inputs() As String =
IO.File.ReadAllLines("Input.txt")
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
lblBy.Visible = False
lblMinus.Visible = False
lblPlus.Visible = False
lblTimes.Visible = False
lblAnswer.Text = ""
For i As Integer = 0 To 15
line = inputs(i)
data = line.Split(","c)
Values(i).real = data(0)
Values(i).imag = data(1)
'Values(i) = (strValues(i))
Next
End Sub
'ALL TEXT FILE VALUE CALCULATIONS
Private Sub btnFileAdd_Click(sender As Object, e As EventArgs) Handles btnFileAdd.Click
'ComplexMath.MathFunctions.Add(Values(0).real, Values(0).imag, Values(1).real, Values(1).imag)
'lstFileResults.Items.AddRange = Values(15)
ValuesString = Values.real(15)
TextBox1.Text = Values(15)
lblBy.Visible = False
lblTimes.Visible = False
lblMinus.Visible = False
lblPlus.Visible = True
End Sub
Private Sub btnFileSubtract_Click(sender As Object, e As EventArgs) Handles btnFileSubtract.Click
lblBy.Visible = False
lblTimes.Visible = False
lblPlus.Visible = False
lblMinus.Visible = True
End Sub
Private Sub btnFileMultiply_Click(sender As Object, e As EventArgs) Handles btnFileMultiply.Click
lblBy.Visible = False
lblPlus.Visible = False
lblMinus.Visible = False
lblTimes.Visible = True
End Sub
Private Sub btnFileDivide_Click(sender As Object, e As EventArgs) Handles btnFileDivide.Click
lblTimes.Visible = False
lblPlus.Visible = False
lblMinus.Visible = False
lblBy.Visible = True
End Sub
'ALL USER VALUE CALCULATIONS
Private Sub btnUserAdd_Click(sender As Object, e As EventArgs) Handles btnUserAdd.Click
Real1 = Val(txtReal1.Text)
Real2 = Val(txtReal2.Text)
Imag1 = Val(txtImag1.Text)
Imag2 = Val(txtImag2.Text)
Answer = ComplexMath.MathFunctions.Add(Real1, Imag1, Real2, Imag2)
lblAnswer.Text = Answer
lblBy.Visible = False
lblTimes.Visible = False
lblMinus.Visible = False
lblPlus.Visible = True
End Sub
Private Sub btnUserSubtract_Click(sender As Object, e As EventArgs) Handles btnUserSubtract.Click
Real1 = Val(txtReal1.Text)
Real2 = Val(txtReal2.Text)
Imag1 = Val(txtImag1.Text)
Imag2 = Val(txtImag2.Text)
Answer = ComplexMath.MathFunctions.Subtract(Real1, Imag1, Real2, Imag2)
lblAnswer.Text = Answer
lblBy.Visible = False
lblTimes.Visible = False
lblPlus.Visible = False
lblMinus.Visible = True
End Sub
Private Sub btnUserMultiply_Click(sender As Object, e As EventArgs) Handles btnUserMultiply.Click
Real1 = Val(txtReal1.Text)
Real2 = Val(txtReal2.Text)
Imag1 = Val(txtImag1.Text)
Imag2 = Val(txtImag2.Text)
Answer = ComplexMath.MathFunctions.Multiply(Real1, Imag1, Real2, Imag2)
lblAnswer.Text = Answer
lblBy.Visible = False
lblPlus.Visible = False
lblMinus.Visible = False
lblTimes.Visible = True
End Sub
Private Sub btnUserDivide_Click(sender As Object, e As EventArgs) Handles btnUserDivide.Click
Real1 = Val(txtReal1.Text)
Real2 = Val(txtReal2.Text)
Imag1 = Val(txtImag1.Text)
Imag2 = Val(txtImag2.Text)
Answer = ComplexMath.MathFunctions.Multiply(Real1, Imag1, Real2, Imag2)
lblAnswer.Text = Answer
lblTimes.Visible = False
lblPlus.Visible = False
lblMinus.Visible = False
lblBy.Visible = True
End Sub
End Class
Can anyone help me with this?
I have a form namely "frmMainMenu" and has a panel in it.
This is my Main Menu form.
![this is my main menu.][1]
and i have this UserControl namely "uscPOS".
When i clicked F8, the panel inside the form will be the parent of the usercontrol.
like this.
what i want to happen is when i click the New Invoice button from my form, the textbox in usercontrol will be enabled. i have this code in my form
Public Class frmMainMenu
Private Sub rbiPOS_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles rbiPOS.Click
Try
Dim bLoad As Boolean = False
If UIPanel.HasChildren Then
If Not TypeOf (UIPanel.Controls(0)) Is uscPOS Then
UIPanel.Controls.Clear()
bLoad = True
End If
Else
bLoad = True
End If
If bLoad Then
Dim f As New uscPOS
f.Parent = UIPanel
f.Dock = DockStyle.Fill
f.Visible = True
End If
rbrPOS.Enabled = True
rbrProducts.Enabled = True
rbrDiscount.Enabled = True
rbrExact.Enabled = True
btnNewInvoice.Enabled = True
btnCancel.Enabled = False
btnSettle.Enabled = False
btnAddtxt.Enabled = False
btnDelete.Enabled = False
btnDiscount.Enabled = False
rbtSenior.Enabled = False
rbtExact.Enabled = False
txtAmountTendered.Enabled = False
txtDiscount.Enabled = False
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Critical Or MsgBoxStyle.OkOnly, "rbiPOS_Click")
End Try
End Sub
Private Sub btnNewInvoice_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNewInvoice.Click
Try
btnNewInvoice.Enabled = False
btnCancel.Enabled = True
btnSettle.Enabled = True
btnAddtxt.Enabled = True
btnDelete.Enabled = True
btnDiscount.Enabled = True
rbtSenior.Enabled = False
rbtExact.Enabled = False
txtAmountTendered.Enabled = False
txtDiscount.Enabled = False
**'starting from this part
Dim f As New uscPOS
f.txtCustomerName.Enabled = True
f.txtCustomerAddress.Enabled = True
f.txtContactNo.Enabled = True
f.txtSearchProductCode.Enabled = True
'i tried to put message box here just to know if this part is happening but the messagebox is displayed
MsgBox("I am able to go to this part of code.")
f.pnecbxSearchProductName.Visible = True
f.pnecbxSearchProductName.Enabled = True
f.pnecbxSearchProductName.Dock = DockStyle.Bottom
f.txtUnitPrice.Enabled = True
f.txtQuantity.Enabled = True
MsgBox("I am at the end of the code.")
'to this part, is not happening.**
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Critical Or MsgBoxStyle.OkOnly, "btNNewInvoice_Click")
End Try
End Sub
End Class
but i can't understand why it didn't enable my textbox in my usercontrol, no errors or warning. can anyone enlighten me with this? i can't move on to my project because of this. help will be much appreciated. thanks..
You create your user control but never add it to your panel.
UIPanel.controls.add(f) 'adds your control to the panel
I basically want a survey document where the user selects a rating such as "always" and "never." They select a rating by hitting a radio button. The ratings are weighted and are averaged into a total score, like a GPA, i.e. always is worth 3, somewhat is worth 2 and each question should be added and then averaged. Below is a section of my code for one question.
How do I take the value at the end after the button is selected and average them for all the questions?
Private Sub RadioButton1_CheckedChanged(sender As Object, e As EventArgs) Handles RadioButton1.CheckedChanged
If RadioButton1.Checked = True Then
RadioButton3.Checked = False
RadioButton2.Checked = False
RadioButton4.Checked = False
RadioButton5.Checked = False
num1 = 2
End If
End Sub
Private Sub RadioButton2_CheckedChanged(sender As Object, e As EventArgs) Handles RadioButton2.CheckedChanged
If RadioButton2.Checked = True Then
RadioButton3.Checked = False
RadioButton1.Checked = False
RadioButton4.Checked = False
RadioButton5.Checked = False
num1 = 3
End If
End Sub
Private Sub RadioButton3_CheckedChanged(sender As Object, e As EventArgs) Handles RadioButton3.CheckedChanged
If RadioButton3.Checked = True Then
RadioButton1.Checked = False
RadioButton2.Checked = False
RadioButton4.Checked = False
RadioButton5.Checked = False
num1 = 1
End If
End Sub
Private Sub RadioButton4_CheckedChanged(sender As Object, e As EventArgs) Handles RadioButton4.CheckedChanged
If RadioButton4.Checked = True Then
RadioButton3.Checked = False
RadioButton2.Checked = False
RadioButton1.Checked = False
RadioButton5.Checked = False
num1 = 0
End If
End Sub
Private Sub RadioButton5_CheckedChanged(sender As Object, e As EventArgs) Handles RadioButton5.CheckedChanged
If RadioButton5.Checked = True Then
RadioButton3.Checked = False
RadioButton2.Checked = False
RadioButton4.Checked = False
RadioButton1.Checked = False
num1 = 0
End If
End Sub
First of all, you can consolidate all of those RadioButton event handlers into ONE handler. Furthermore, you don't have to "uncheck" the other RadioButtons in the group as this will be done automatically for you. Finally, create a separate method that computes the rating and updates the form, then call that method at the bottom of the handler.
That might look something like this:
Private num1 As Integer
Private Sub set1_CheckedChanged(sender As Object, e As EventArgs) Handles _
RadioButton1.CheckedChanged, RadioButton2.CheckedChanged, RadioButton3.CheckedChanged, _
RadioButton4.CheckedChanged, RadioButton5.CheckedChanged
If RadioButton1.Checked Then
num1 = 2
ElseIf RadioButton2.Checked Then
num1 = 3
ElseIf RadioButton3.Checked Then
num1 = 1
ElseIf RadioButton4.Checked Then
num1 = 0
ElseIf RadioButton5.Checked Then
num1 = 0
End If
UpdateRating()
End Sub
Private Sub UpdateRating()
' ... compute the rating using "num1", "num2", "num3", etc ...
' ... then update the GUI with the new value ...
End Sub
Note that all five RadioButtons are listed after the "Handles" keyword making them all fire the same handler. You can do a similar thing for each group of RadioButtons...just make sure each set of RadioButtons is in its OWN container like a GroupBox or Panel. A RadioButton is mutually exclusive with all other RadioButttons in its own container.
I'm not so sure about your case .. but you can try this
Declare your var that will count all result ..
Dim num1 as Integer
Dim num2 as Integer '--> for other group radiobuttons
Dim num3 as Integer '--> for other group radiobuttons
Dim nTotal as Integer
Dim nAvg as Integer
Do this in each checkchanged
Private Sub RadioButton_CheckedChanged(..) Handles RadioButton1_CheckedChanged, RadioButton2_CheckedChanged, .....
'codes
countit()
End Sub
Sub CountIt()
nTotal = num1 + num2 + num3
nAvg = (num1 + num2 + num3) / 3
End Sub
So at present I am learning VB and I have a project in which I have to display a picture box based on:
Which radio box is checked
and
if a checkbox to make the picture box visible is checked. As someone who values clean, good code this is my code and it horrifies me. My question, is there some way to condense the following using cases or some other construct I don't know in VB.net?
If CheckBox1.Checked = False Then
BooksPictureBox.Visible = False
MusicPictureBox.Visible = False
PeriodicalsPictureBox.Visible = False
CoffeeBarPictureBox.Visible = False
End If
If RadioButton1.Checked And CheckBox1.Checked = True Then
BooksPictureBox.Visible = True
MusicPictureBox.Visible = False
PeriodicalsPictureBox.Visible = False
CoffeeBarPictureBox.Visible = False
End If
If RadioButton2.Checked And CheckBox1.Checked = True Then
BooksPictureBox.Visible = False
MusicPictureBox.Visible = True
PeriodicalsPictureBox.Visible = False
CoffeeBarPictureBox.Visible = False
End If
If RadioButton3.Checked And CheckBox1.Checked = True Then
BooksPictureBox.Visible = False
MusicPictureBox.Visible = False
PeriodicalsPictureBox.Visible = True
CoffeeBarPictureBox.Visible = False
End If
If RadioButton4.Checked And CheckBox1.Checked = True Then
BooksPictureBox.Visible = False
MusicPictureBox.Visible = False
PeriodicalsPictureBox.Visible = False
CoffeeBarPictureBox.Visible = True
End If
Note- all the images stack on one another, and all of them start without being visible.
I would create a SUb that sets all picBoxes to not visible
Private Sub setInvisible
BooksPictureBox.Visible = False
MusicPictureBox.Visible = False
PeriodicalsPictureBox.Visible = False
CoffeeBarPictureBox.Visible = False
End sub
Then another routine
Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged
setInvisible
if checkbox1.checked = false then exit sub
if radiobutton1.checked = true then bookspicturebox.visible = true
if radiobutton2.checked = true then musicpicturebox.visible = true
etc...
End Sub
Of course, an easier way would be to just have the image dynamically load based upon radio button selection.
Maybe this?
' Set first condition, the check box must be checked
BooksPictureBox.Visible = CheckBox1.Checked
MusicPictureBox.Visible = CheckBox1.Checked
PeriodicalsPictureBox.Visible = CheckBox1.Checked
CoffeeBarPictureBox.Visible = CheckBox1.Checked
' Set individual conditions, the radio button must be checked
BooksPictureBox.Visible = RadioButton1.Checked
MusicPictureBox.Visible = RadioButton2.Checked
PeriodicalsPictureBox.Visible = RadioButton3.Checked
CoffeeBarPictureBox.Visible = RadioButton4.Checked
Edit: Or, you could take a different Clean Code approach :)
ShowOrHidePictureBoxes()
...
Private Sub ShowOrHidePictureBoxes
ShowOrHideBooks()
ShowOrHideMusic()
ShowOrHidePeriodicals()
ShowOrHideCoffeeBar()
End Sub
Private Sub ShowOrHideBooks
BooksPictureBox.Visible = RadioButton1.Checked And CheckBox1.Checked
End Sub
Private Sub ShowOrHideMusic
BooksPictureBox.Visible = RadioButton2.Checked And CheckBox1.Checked
End Sub
Private Sub ShowOrHidePeriodicals
BooksPictureBox.Visible = RadioButton3.Checked And CheckBox1.Checked
End Sub
Private Sub ShowOrHideCoffeeBar
BooksPictureBox.Visible = RadioButton4.Checked And CheckBox1.Checked
End Sub
You could take this further in two ways:
Extract the logic out into a shared helper class to re-use throughout the application, or even into actual models which represent the business concepts in the application. This will depend heavily on how the rest of the application is to be designed, what the business needs are, etc. In the context of this question it's more of a thought exercise than a real answer.
Name your controls better so that the code looks more expressive. Things like CheckBox1 and RadioButton1 pollute the code more than the If statements did :)
You could get it down to something like:
Dim fBooksVisible As Boolean
Dim fMusicVisible As Boolean
Dim fPeriodicalsVisible As Boolean
Dim fCoffeeBarVisible As Boolean
If CheckBox1.Checked Then
fBooksVisible = RadioButton1.Checked
fMusicVisible = RadioButton2.Checked
fPeriodicalsVisible = RadioButton3.Checked
fCoffeeBarVisible = RadioButton4.Checked
End If
BooksPictureBox.Visible = fBooksVisible
MusicPictureBox.Visible = fMusicVisible
PeriodicalsPictureBox.Visible = fPeriodicalsVisible
CoffeeBarPictureBox.Visible = fCoffeeBarVisible
or even:
BooksPictureBox.Visible = RadioButton1.Checked AndAlso CheckBox1.Checked
MusicPictureBox.Visible = RadioButton2.Checked AndAlso CheckBox1.Checked
PeriodicalsPictureBox.Visible = RadioButton3.Checked AndAlso CheckBox1.Checked
CoffeeBarPictureBox.Visible = RadioButton4.Checked AndAlso CheckBox1.Checked