How can I end my loop? - vb.net

I made a loop to show the balance when entered a name, but when I try to do it a second time. It doesn't return another output(messagebox). How can I end/restart the loop?
Public Class Form1
Dim intMax_Subscript As Integer = 7
Dim arrayNames(intMax_Subscript) As String
Dim arrayBalance(intMax_Subscript) As Double
Dim found As Boolean
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
CBO1.Items.Add("John One")
arrayNames(0) = CStr(CBO1.Items(0))
CBO1.Items.Add("Jack Two")
arrayNames(1) = CStr(CBO1.Items(1))
CBO1.Items.Add("John Three")
arrayNames(2) = CStr(CBO1.Items(2))
CBO1.Items.Add("Jack Four")
arrayNames(3) = CStr(CBO1.Items(3))
CBO1.Items.Add("John Five")
arrayNames(4) = CStr(CBO1.Items(4))
CBO1.Items.Add("Jack Six")
arrayNames(5) = CStr(CBO1.Items(5))
CBO1.Items.Add("John Seven")
arrayNames(6) = CStr(CBO1.Items(6))
CBO1.Items.Add("Jack Eight")
arrayNames(7) = CStr(CBO1.Items(7))
CBO2.Items.Add("235.50")
arrayBalance(0) = CDbl(CBO2.Items(0))
CBO2.Items.Add("78943.98")
arrayBalance(1) = CDbl(CBO2.Items(1))
CBO2.Items.Add("230781.10")
arrayBalance(2) = CDbl(CBO2.Items(2))
CBO2.Items.Add("78362.00")
arrayBalance(3) = CDbl(CBO2.Items(3))
CBO2.Items.Add("12097.20")
arrayBalance(4) = CDbl(CBO2.Items(4))
CBO2.Items.Add("89267.34")
arrayBalance(5) = CDbl(CBO2.Items(5))
CBO2.Items.Add("34959.06")
arrayBalance(6) = CDbl(CBO2.Items(6))
CBO2.Items.Add("559284.50")
arrayBalance(7) = CDbl(CBO2.Items(7))
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBalance.Click
Dim input As String = InputBox("Input a name")
Dim intcount As Integer = -1
Dim intSubscript As Integer = 0
Do While Not found And intcount < arrayNames.Length
If arrayNames(intSubscript) = input Then
found = True
MessageBox.Show("The balance of " & input & "'s is " & arrayBalance(intSubscript))
intSubscript = 0
intcount = -1
End If
intSubscript += 1
Loop
If Not arrayNames.Contains(input) Then
MessageBox.Show("Error: Name not found.")
End If
End Sub

You Need to reset the found to false after showing message box
If Not arrayNames.Contains(input) Then
MessageBox.Show("Error: Name not found.")
found = False
End If

you don't need the 'found' variable at all
Do While intcount < arrayNames.Length
If arrayNames(intSubscript) = input Then
MessageBox.Show("The balance of " & input & "'s is " & arrayBalance(intSubscript))
intSubscript = 0
Exit Do
End If
intSubscript += 1
Loop

Related

how to count the number of check boxes checked in visual basic?

Private Sub Btn_Cast_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Btn_Cast.Click
Dim Counter As Integer = 0
If ChkBox_Barton.CheckState = 1 And ChkBox_Martin.CheckState = 1 And ChkBox_Richards.CheckState = 1 Then
MsgBox("Don't vote for more than 2")
End If
Dim Count_Barton As Integer
Dim Count_Martin As Integer
Dim Count_Richards As Integer
If ChkBox_Barton.Checked Then Count_Barton += 1
If ChkBox_Martin.Checked = 1 Then Count_Martin += 1
If ChkBox_Richards.CheckState = 1 Then Count_Richards += 1
End Sub
Problem is, I'm trying to count it everytime, then let it reset and count again.
Example. I select Barton one time, click vote, then i should be able to select someone new and click vote and it should keep counting.
what can I do?
I need to then display my results. Should I just hold the number in a text or Integer file then display it that way?
I quickly set up your application myself.
Following Code applies to this GUI:
Code:
Public Class VoteCounter
Dim intCountBarton As Integer
Dim intCountMartin As Integer
Dim intCountRichards As Integer
Private Sub ButtonVote_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonVote.Click
If CheckBoxBarton.CheckState = 1 And CheckBoxMartin.CheckState = 1 And CheckBoxRichards.CheckState = 1 Then
MsgBox("Don't vote for more than 2")
CheckBoxBarton.Checked = False
CheckBoxMartin.Checked = False
CheckBoxRichards.Checked = False
End If
If CheckBoxBarton.Checked Then
intCountBarton += 1
End If
If CheckBoxMartin.Checked Then
intCountMartin = intCountMartin + 1
End If
If CheckBoxRichards.Checked Then
intCountRichards = intCountRichards + 1
End If
CheckBoxBarton.Checked = False
CheckBoxMartin.Checked = False
CheckBoxRichards.Checked = False
End Sub
Private Sub ButtonResult_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonResult.Click
MsgBox("Barton: " & intCountBarton & vbNewLine & "Martin: " & intCountMartin & vbNewLine & "Richards: " & intCountRichards)
End Sub
Private Sub ButtonReset_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonReset.Click
CheckBoxBarton.Checked = False
CheckBoxMartin.Checked = False
CheckBoxRichards.Checked = False
intCountBarton = 0
intCountMartin = 0
intCountRichards = 0
End Sub
End Class
Dim Count_Barton As Integer = 0
Dim Count_Martin As Integer = 0
Dim Count_Richards As Integer = 0
Private Sub Btn_Cast_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Btn_Cast.Click
Dim Counter As Integer = 0 'NOT SURE WHAT THIS IS DOING... NOT BEING USED
If ChkBox_Barton.CheckState = 1 And ChkBox_Martin.CheckState = 1 And ChkBox_Richards.CheckState = 1 Then
MsgBox("Don't vote for more than 2")
Else
If ChkBox_Barton.Checked Then Count_Barton += 1
If ChkBox_Martin.Checked = 1 Then Count_Martin += 1
If ChkBox_Richards.CheckState = 1 Then Count_Richards += 1
End If
End Sub

Score not being calculated correctly

Hi I'm created a program for a project and I've now started running some tests and the score for the user isn't being calculated correctly and I believe that it can't compare the answer given to the correct answer. I'm very confused and need any help that can be given. My code looks like this, any confusing parts and I'll try and explain.
Imports System.IO
Public Class QuestionScreen
Dim score As Integer = 0
Dim count As Integer
Dim Difficulty_ext As String
Dim questions, answers As New List(Of String)()
Private i As Integer
Sub ReadFile()
If Main.Diff_DDown.Text = "Easy" Then
Difficulty_ext = "questions - Easy"
ElseIf Main.Diff_DDown.Text = "Medium" Then
Difficulty_ext = "questions - Medium"
Else
Difficulty_ext = "questions - Difficult"
End If
Randomize()
Dim countline = File.ReadAllLines("c:\Users\Alice\Desktop\programme files\" & Difficulty_ext & ".txt").Length
Dim numline As Integer
Dim values() As String
Using sr As New StreamReader("c:\Users\Alice\Desktop\programme files\" & Difficulty_ext & ".txt")
While Not sr.EndOfStream
values = sr.ReadLine().Split(","c)
questions.Add(values(0))
answers.Add(values(1))
End While
End Using
numline = Int(Rnd() * countline)
For i As Integer = 0 To numline
Question.Text = questions(i)
Act_ANS.Text = answers(i)
Next
End Sub
Private Sub Pass_Btn_Click(sender As Object, e As EventArgs) Handles Pass_Btn.Click
If count < 10 Then
Call ReadFile()
count = count + 1
Ans_TxtBx.Text = ""
Hid_Score.Text = score
Else
ResultsScreen.Show()
Me.Hide()
End If
End Sub
Public Sub Submit_Btn_Click(sender As Object, e As EventArgs) Handles Submit_Btn.Click
If count < 10 Then
Call ReadFile()
count = count + 1
If Ans_TxtBx.Text = answers(i) Then
score = score + 1
End If
Hid_Score.Text = score
Else
ResultsScreen.Show()
Me.Hide()
count = 0
End If
Ans_TxtBx.Text = ""
End Sub
Private Sub QuestionScreen_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Call ReadFile()
End Sub
End Class
OK..... Try this, I have debugged your code trying to leave it pretty much as you had it, there were a number of problems, nothing major just a few lines of code in the wrong place....
Imports System.IO
Public Class Form1
Dim score As Integer = 0
Dim count As Integer
Dim Difficulty_ext As String
Dim questions, answers As New List(Of String)()
Private i As Integer
Sub ReadFile()
If Diff_DDown.Text = "Easy" Then
Difficulty_ext = "questions - Easy"
ElseIf Diff_DDown.Text = "Medium" Then
Difficulty_ext = "questions - Medium"
Else
Difficulty_ext = "questions - Difficult"
End If
Randomize()
Try
Dim countline = File.ReadAllLines("c:\Users\Alice\Desktop\programme files\" & Difficulty_ext & ".txt").Length
Dim numline As Integer
Dim values() As String
' clear the list of questions and answers
answers.Clear()
questions.Clear()
'''''''''''''''''''''''''''''''''''''''''
Using sr As New StreamReader("c:\Users\Alice\Desktop\programme files\" & Difficulty_ext & ".txt")
While Not sr.EndOfStream
values = sr.ReadLine().Split(","c)
questions.Add(values(0))
answers.Add(values(1))
End While
End Using
numline = Int(Rnd() * countline)
For i = 0 To numline
Question.Text = questions(i)
Act_ANS.Text = answers(i)
Next
Catch ex As Exception
End Try
End Sub
Private Sub Pass_Btn_Click(sender As Object, e As EventArgs) Handles Pass_Btn.Click
If count < 10 Then
count = count + 1
Ans_TxtBx.Text = ""
Hid_Score.Text = score
Else
ResultsScreen.Show()
Me.Hide()
End If
Call ReadFile() ' move this to the bottom
End Sub
Public Sub Submit_Btn_Click(sender As Object, e As EventArgs) Handles Submit_Btn.Click
If count < 10 Then
count = count + 1
If Ans_TxtBx.Text = answers(i - 1) Then ' need to subtract 1 here
score = score + 1
End If
Hid_Score.Text = score
Else
ResultsScreen.Show()
Me.Hide()
count = 0
End If
Ans_TxtBx.Text = ""
Call ReadFile() ' move this to the bottom
End Sub
Private Sub QuestionScreen_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Call ReadFile()
End Sub
End Class

IndexOutOfRangeException was Unhandled. Cannot find table 0

can anyone please help on how to fix this error? im getting an error "Error:Syntax error(missing operator)in query expression '''ans'." this is my code:
Imports System.Data
Imports System.Data.OleDb
Public Class frmExam : Inherits System.Windows.Forms.Form
Dim ds As New DataSet()
Dim qno() As Integer
Dim pos As Integer
Private Sub btnFinish_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFinish.Click
ProcessAnswer()
Dim i, marks As Integer
Dim dr As DataRow
marks = 0
For i = 0 To NOQ - 1
dr = ds.Tables(0).Rows(qno(i))
If Not IsDBNull(dr.Item("ans")) AndAlso dr.Item("CorrectAns") = dr.Item("ans") Then
marks += 1
End If
Next
Try
con.Open()
Dim cmd As New OleDbCommand("insert into stud values(stud.nextval,'" & SubjectCode & "','" & Username & "','" & marks & ")", con)
MsgBox(cmd.CommandText)
cmd.ExecuteNonQuery()
Dim msg As String
msg = "UserName : " & Username & ControlChars.CrLf & _
"Subject : " & SubjectCode & ControlChars.CrLf & _
"Total Questions : " & NOQ & ControlChars.CrLf & _
"Marks : " & marks
MsgBox(msg, "Result")
Catch ex As Exception
MsgBox(ex.Message)
Finally
If con.State <> ConnectionState.Closed Then
con.Close()
End If
End Try
Me.Dispose()
End Sub
Private Sub frmExam_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
ReDim qno(NOQ)
Try
Dim da As New OleDbDataAdapter("select Question, Ans1, Ans2, Ans3, Ans4, CorrectAns, QType, '' ans from question where SubjectCode = " & SubjectCode, con)
da.Fill(ds, "question")
Catch ex As Exception
MsgBox("Error:" & ex.Message)
Me.Dispose()
End Try
Randomize()
Dim totrows As Integer
totrows = ds.Tables(0).Rows.Count
Dim i, r, j As Integer
Dim present As Boolean
i = 0
Do While i < 5
r = CInt((totrows - 1) * Rnd())
present = False
For j = 0 To i
If r = qno(j) Then
present = True
Exit For
End If
Next
If Not present Then
qno(i) = r
i = i + 1
End If
Loop
pos = 0
DisplayQuestion()
End Sub
Sub DisplayQuestion()
Dim row As DataRow
lblQno.Text = Str(pos + 1) & "/" & NOQ
lblSubcode.Text = "Subject : " & SubjectCode
row = ds.Tables(0).Rows(qno(pos))
txtQuestion.Text = row.Item(0)
txtAns1.Text = row.Item(1)
txtAns2.Text = row.Item(2)
txtAns3.Text = row.Item(3)
txtAns4.Text = row.Item(4)
lblQNo2.Text = Str(pos + 1) & "/" & NOQ
lblSubCode2.Text = "Subject:" & SubjectCode
row = ds.Tables(0).Rows(qno(pos))
txtQuestion2.Text = row.Item(0)
txtAnsTrue.Text = row.Item(1)
txtAnsFalse.Text = row.Item(2)
lblQNo3.Text = Str(pos + 1) & "/" & NOQ
lblSubcode.Text = "Subject : " & SubjectCode
row = ds.Tables(0).Rows(qno(pos))
txtQuestion3.Text = row.Item(1)
txtAns.Text = row.Item(2)
End Sub
Private Sub btnNext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNext.Click
ProcessAnswer()
If pos < NOQ - 1 Then
pos = pos + 1
DisplayQuestion()
Else
Beep()
End If
End Sub
Private Sub btnPrev_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPrev.Click
ProcessAnswer()
If pos > 0 Then
pos = pos - 1
DisplayQuestion()
End If
End Sub
Public Sub ProcessAnswer()
Dim row As DataRow
Dim ans As String = ""
row = ds.Tables(0).Rows(qno(pos))
If rdbtnAns1.Checked Then
ans = "1"
End If
If rdbtnAns2.Checked Then
ans = "2"
End If
If rdbtnAns3.Checked Then
ans = "3"
End If
If rdbtnAns4.Checked Then
ans = "4"
End If
If rdbtnTrue.Checked Then
ans = "1"
End If
If rdbtnFalse.Checked Then
ans = "2"
End If
If txtAns.Text = "" Then
ans = "txtAns"
End If
ds.Tables(0).Rows(qno(pos)).Item("Ans1") = ans
End Sub
Private Sub btnPrev2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPrev2.Click
ProcessAnswer()
If pos > 0 Then
pos = pos - 1
DisplayQuestion()
End If
End Sub
Private Sub btnNext2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNext2.Click
ProcessAnswer()
If pos < NOQ - 1 Then
pos = pos + 1
DisplayQuestion()
Else
Beep()
End If
End Sub
Private Sub btnPrev3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPrev3.Click
ProcessAnswer()
If pos > 0 Then
pos = pos - 1
DisplayQuestion()
End If
End Sub
Private Sub btnNext3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNext3.Click
ProcessAnswer()
If pos < NOQ - 1 Then
pos = pos + 1
DisplayQuestion()
Else
Beep()
End If
End Sub
End Class
this is the highlighted texxt:totrows = ds.Tables(0).Rows.Count
When you want to use an alias for a field expression, Access requires you to use the AS keyword.
This would fail ...
select Question, Ans1, Ans2, Ans3, Ans4, CorrectAns, QType, '' ans from question
This could work ...
select Question, Ans1, Ans2, Ans3, Ans4, CorrectAns, QType, '' AS ans from question
However, I would be uneasy with a field whose name matched the table name. If you can't rename that field, alias the table, and qualify the fields with the table alias.
select q.Question, q.Ans1, q.Ans2, q.Ans3, q.Ans4, q.CorrectAns, q.QType, '' AS ans from question AS q

not accessible in this context because it is 'Private' [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 1 year ago.
Improve this question
I'm writing some code for a calculator and I keep getting this error. I have the math functions in another class but the variables from form1 are not accessible. Below is my code.
I've also tried changing my Dim variables to public but that also doesn't work.
Public Class Form1
'create a value to keep track of whether the calculation is complete so the calculator can revert to zero for new calculations
Dim state As Integer
'create values to store information on numbers and signs entered as well as the answer returned
Dim one As Double
Dim two As Double
Dim ans As Double
Dim sign As Char
Public Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
'when "Return" or "Enter" Key is selected button 15 is clicked (seems to only work when textbox selected????)
Me.AcceptButton = Button15
'change the title of the form
Me.Text = "Simple Calculator"
'label the buttons logically
Button1.Text = "1"
Button2.Text = "2"
Button3.Text = "3"
Button4.Text = "4"
Button5.Text = "5"
Button6.Text = "6"
Button7.Text = "7"
Button8.Text = "8"
Button9.Text = "9"
Button10.Text = "0"
Button11.Text = "+"
Button12.Text = "-"
Button13.Text = "X"
Button14.Text = "/"
Button15.Text = "Calc"
Button16.Text = "About Me"
Button17.Text = "Clear"
'allows form to revcieve key events
Me.KeyPreview = True
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
'create action when button 1 is clicked
'if state is 1 then previous calculation was solved, then clear textbox to allow for new input
If state = 1 Then
TextBox1.Text = ""
'insert 1 into textbox
Dim Int1 As Integer = 1
TextBox1.Text = TextBox1.Text & Int1
'return state of calculator to zero to designate that calculation has NOT been solved
state = 0
Else
'else insert 1 into textbox
Dim Int1 As Integer = 1
TextBox1.Text = TextBox1.Text & Int1
End If
End Sub
' the above function for each numbered button
Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
If state = 1 Then
TextBox1.Text = ""
Dim Int2 As Integer = 2
TextBox1.Text = TextBox1.Text & Int2
state = 0
Else
Dim Int2 As Integer = 2
TextBox1.Text = TextBox1.Text & Int2
End If
End Sub
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
If state = 1 Then
TextBox1.Text = ""
Dim Int3 As Integer = 3
TextBox1.Text = TextBox1.Text & Int3
state = 0
Else
Dim Int3 As Integer = 3
TextBox1.Text = TextBox1.Text & Int3
End If
End Sub
Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
If state = 1 Then
TextBox1.Text = ""
Dim Int4 As Integer = 4
TextBox1.Text = TextBox1.Text & Int4
state = 0
Else
Dim Int4 As Integer = 4
TextBox1.Text = TextBox1.Text & Int4
End If
End Sub
Private Sub Button5_Click(sender As Object, e As EventArgs) Handles Button5.Click
If state = 1 Then
TextBox1.Text = ""
Dim Int5 As Integer = 5
TextBox1.Text = TextBox1.Text & Int5
state = 0
Else
Dim Int5 As Integer = 5
TextBox1.Text = TextBox1.Text & Int5
End If
End Sub
Private Sub Button6_Click(sender As Object, e As EventArgs) Handles Button6.Click
If state = 1 Then
TextBox1.Text = ""
Dim Int6 As Integer = 6
TextBox1.Text = TextBox1.Text & Int6
state = 0
Else
Dim Int6 As Integer = 6
TextBox1.Text = TextBox1.Text & Int6
End If
End Sub
Private Sub Button7_Click(sender As Object, e As EventArgs) Handles Button7.Click
If state = 1 Then
TextBox1.Text = ""
Dim Int7 As Integer = 7
TextBox1.Text = TextBox1.Text & Int7
state = 0
Else
Dim Int7 As Integer = 7
TextBox1.Text = TextBox1.Text & Int7
End If
End Sub
Private Sub Button8_Click(sender As Object, e As EventArgs) Handles Button8.Click
If state = 1 Then
TextBox1.Text = ""
Dim Int8 As Integer = 8
TextBox1.Text = TextBox1.Text & Int8
state = 0
Else
Dim Int8 As Integer = 8
TextBox1.Text = TextBox1.Text & Int8
End If
End Sub
Private Sub Button9_Click(sender As Object, e As EventArgs) Handles Button9.Click
If state = 1 Then
TextBox1.Text = ""
Dim Int9 As Integer = 9
TextBox1.Text = TextBox1.Text & Int9
state = 0
Else
Dim Int9 As Integer = 9
TextBox1.Text = TextBox1.Text & Int9
End If
End Sub
Private Sub Button10_Click(sender As Object, e As EventArgs) Handles Button10.Click
If state = 1 Then
TextBox1.Text = ""
Dim Int0 As Integer = 0
TextBox1.Text = TextBox1.Text & Int0
state = 0
Else
Dim Int0 As Integer = 0
TextBox1.Text = TextBox1.Text & Int0
End If
End Sub
Private Sub Button11_Click(sender As Object, e As EventArgs) Handles Button11.Click
'create an action for when addition button is clicked
Try
'when button is clicked dim sign and text in textbox
sign = "+"
one = TextBox1.Text
TextBox1.Text = ""
Catch ex As Exception
TextBox1.Text = "Error" ' if error occurs return error in textbox
state = 1 'if error occurs return state to 1 to allow for new calculation
End Try
End Sub
'repeat the above action for remainder of arithmic functions
Private Sub Button12_Click(sender As Object, e As EventArgs) Handles Button12.Click
Try
'when button is clicked dim sign and text in textbox
sign = "-"
one = TextBox1.Text
TextBox1.Text = ""
Catch ex As Exception
TextBox1.Text = "Error" ' if error occurs return error in textbox
state = 1 'if error occurs return state to 1 to allow for new calculation
End Try
End Sub
Private Sub Button13_Click(sender As Object, e As EventArgs) Handles Button13.Click
Try
sign = "*"
one = TextBox1.Text
TextBox1.Text = ""
Catch ex As Exception
TextBox1.Text = "Error" ' if error occurs return error in textbox
state = 1 'if error occurs return state to 1 to allow for new calculation
End Try
End Sub
Private Sub Button14_Click(sender As Object, e As EventArgs) Handles Button14.Click
Try
sign = "/"
one = TextBox1.Text
TextBox1.Text = ""
Catch ex As Exception
TextBox1.Text = "Error"
state = 1 'if error occurs return state to 1 to allow for new calculation
End Try
End Sub
Private Sub Button15_Click(sender As Object, e As EventArgs) Handles Button15.Click
'run functions based on sign stored during calculation
Try
two = TextBox1.Text
If sign = "+" Then
Calculator2.Math.add()
ElseIf sign = "-" Then
Calculator2.Math.minus()
ElseIf sign = "*" Then
Calculator2.Math.multiply()
ElseIf sign = "/" Then
Calculator2.Math.divide()
End If
'if user attempts to divide by zero return divide by zero error in textbox
If TextBox1.Text = "Infinity" Then
TextBox1.Text = "Divide by Zero Error"
state = 1 'if error occurs return state to 1 to allow for new calculation
End If
Catch ex As Exception
TextBox1.Text = "Error"
state = 1 'if error occurs return state to 1 to allow for new calculation
End Try
End Sub
Private Sub Button16_Click(sender As Object, e As EventArgs) Handles Button16.Click
'create message box that provides information about author
Dim msg = "Student Name: Emily Wong" & vbCrLf & "Student Number: 0692740" ' Define the message you want to see inside the message box.
Dim title = "About Me" ' Define a title for the message box.
Dim style = MsgBoxStyle.OkOnly ' make an ok button for the msg box
Dim response = MsgBox(msg, style, title)
End Sub
Private Sub Button17_Click(sender As Object, e As EventArgs) Handles Button17.Click
'create a clear button to clear textboxes when clicked and reset state of calculator
TextBox1.Text = ""
state = 0
End Sub
And this is my other class
Public Class Math
Inherits Form1
'create funtions for add,sub, multiply, and divide features
Sub add()
ans = one + two 'creates calculation of the entered numbers
TextBox1.Text = ans 'returns answer into the textbox
state = 1 'returns state to 1 to show that calculation has occured
End Sub
Sub minus()
ans = one - two
TextBox1.Text = ans
state = 1
End Sub
Sub multiply()
ans = one * two
TextBox1.Text = ans
state = 1
End Sub
Sub divide()
ans = one / two
TextBox1.Text = ans
state = 1
End Sub
End Class
state is a private variable in Form1. You can't access from code outside of Form1. Your Math class cannot reference state. Remove the calls to state from the Math class code. An outside class should not be changing the state of another object in anycase.
Try this instead:
Public Class accounting
Dim Operand1 As Double
Dim Operand2 As Double
Dim [Operator] As String
These are the button from 1 - 0
Private Sub Button6_Click_1(sender As Object, e As EventArgs) Handles Button9.Click, Button8.Click, Button7.Click, Button6.Click, Button5.Click, Button4.Click, Button19.Click, Button12.Click, Button11.Click, Button10.Click
txtans.Text = txtans.Text & sender.text
End Sub
This button is for period/point
Private Sub Button18_Click(sender As Object, e As EventArgs) Handles Button18.Click
If InStr(txtans.Text, ".") > 0 Then
Exit Sub
Else
txtans.Text = txtans.Text & "."
End If
End Sub
This button is for clear or "C" in calculator
Private Sub Button20_Click(sender As Object, e As EventArgs) Handles Button20.Click
txtans.Text = ""
End Sub
These are for add,subtract,divide, and multiply
Private Sub Buttonadd_Click(sender As Object, e As EventArgs) Handles Button13.Click
Operand1 = Val(txtans.Text)
txtans.Text = ""
txtans.Focus()
[Operator] = "+"
End Sub
Private Sub Buttondivide_Click(sender As Object, e As EventArgs) Handles Button15.Click
Operand1 = Val(txtans.Text)
txtans.Text = ""
txtans.Focus()
[Operator] = "-"
End Sub
Private Sub Buttonsubtract_Click(sender As Object, e As EventArgs) Handles Button16.Click
Operand1 = Val(txtans.Text)
txtans.Text = ""
txtans.Focus()
[Operator] = "*"
End Sub
Private Sub Buttonmultiply_Click(sender As Object, e As EventArgs) Handles Button14.Click
Operand1 = Val(txtans.Text)
txtans.Text = ""
txtans.Focus()
[Operator] = "/"
End Sub
This button is for "=" sign
Private Sub Buttoneequal_Click(sender As Object, e As EventArgs) Handles Button17.Click
Dim Result As Double
Operand2 = Val(txtans.Text)
'If [Operator] = "+" Then
' Result = Operand1 + Operand2
'ElseIf [Operator] = "-" Then
' Result = Operand1 - Operand2
'ElseIf [Operator] = "/" Then
' Result = Operand1 / Operand2
'ElseIf [Operator] = "*" Then
' Result = Operand1 * Operand2
'End If
Select Case [Operator]
Case "+"
Result = Operand1 + Operand2
txtans.Text = Result.ToString("#,###.00")
Case "-"
Result = Operand1 - Operand2
txtans.Text = Result.ToString("#,###.00")
Case "/"
Result = Operand1 / Operand2
txtans.Text = Result.ToString("#,###.00")
Case "*"
Result = Operand1 * Operand2
txtans.Text = Result.ToString("#,###.00")
End Select
txtans.Text = Result.ToString("#,###.00")
End Sub
This button is for backspace effect.
Private Sub Buttondel_Click(sender As Object, e As EventArgs) Handles Button21.Click
If txtans.Text < " " Then
txtans.Text = Mid(txtans.Text, 1, Len(txtans.Text) - 1 + 1)
Else
txtans.Text = Mid(txtans.Text, 1, Len(txtans.Text) - 1)
End If
End Sub
Note that "txtans.text" is the textbox where the user inputs and where the output shows.

"Conversion from string "" to type 'Double' is not valid."

I keep getting the error Conversion from string "" to type 'Double' is not valid. I know that it means i am trying to convert nothing into a integer and the compiler doesn't like that, but i can't find where in my program because it only happens when I build my program and not in debug. Sorry I can't give more information.
Imports System.IO
Imports System.Text
Public Class frmindex
'Variables
Dim addworld As String
Dim root As String
Dim allownether As String
Dim pvp As String
Dim whitelist As String
Dim spawnmonsters As String
Dim onlinemode As String
Dim spawnanimals As String
Dim bit As String
Dim allowflight As String
Dim launch As String
Dim serverfile As String
Dim safeserverfile As String
Dim ram As ULong
Dim halfram As Integer
Dim serverapplication As String
Dim filter As String
Private Sub frmindex_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Finds Half of the ram of the computer and -1
ram = My.Computer.Info.TotalPhysicalMemory
halfram = ((ram / "1,048,576") / "2") - "1"
nudram.Maximum = halfram
If nudram.Value = "" Or "1024" Then
nudram.Value = halfram
End If
If txbserverfile.Text = "" Then
txbserverfile.Text = CurDir() + "\" + serverapplication
End If
If cmbserverapplication.Text = "Exe Server" Then
serverapplication = "minecraft_server.exe"
lblram.Visible = False
nudram.Visible = False
filter = "Exe Server|*.exe|All Files|*.*"
ElseIf cmbserverapplication.Text = "Jar Server" Then
serverapplication = "minecraft_server.jar"
lblram.Visible = True
nudram.Visible = True
filter = "Jar Server|*.jar|All Files|*.*"
ElseIf cmbserverapplication.Text = "Bukkit Server" Then
serverapplication = "craftbukkit-0.0.1-SNAPSHOT.jar"
lblram.Visible = False
nudram.Visible = False
filter = "Bukkit Server|*.jar|All Files|*.*"
End If
If nudviewdistance.Text = "" Then
nudviewdistance.Text = "10"
End If
'finds load files
If cmbserverapplication.Text = "Exe Server" Then
lblram.Visible = False
nudram.Visible = False
ElseIf cmbserverapplication.Text = "Jar Server" Then
lblram.Visible = True
nudram.Visible = True
ElseIf cmbserverapplication.Text = "Bukkit Server" Then
lblram.Visible = False
nudram.Visible = False
End If
'Checks if save folder exists if not creates one
If (Not System.IO.Directory.Exists(root + "\setting")) Then
System.IO.Directory.CreateDirectory(root + "\setting")
End If
'loads world settings
If File.Exists(root + "\setting\world.txt") Then
For Each line As String In File.ReadLines(root + "\setting\world.txt")
If line.Length <> 0 Then
cmbworld.Items.Add(line)
End If
Next line
End If
'loads ip
If File.Exists(root + "\setting\ip.txt") Then
For Each line As String In File.ReadLines(root + "\setting\ip.txt")
If line.Length <> 0 Then
cmbip.Items.Add(line)
End If
Next line
End If
'loads levelseed
If File.Exists(root + "\setting\levelseed.txt") Then
For Each line As String In File.ReadLines(root + "\setting\levelseed.txt")
If line.Length <> 0 Then
cmblevelseed.Items.Add(line)
End If
Next line
End If
If File.Exists(root + "\banned-players.txt") Then
For Each line As String In File.ReadLines(root + "\banned-players.txt")
If line.Length <> 0 Then
cmbbannedplayers.Items.Add(line)
End If
Next line
End If
If File.Exists(root + "\banned-ips.txt") Then
For Each line As String In File.ReadLines(root + "\banned-ips.txt")
If line.Length <> 0 Then
cmbbannedips.Items.Add(line)
End If
Next line
End If
If File.Exists(root + "\ops.txt") Then
For Each line As String In File.ReadLines(root + "\ops.txt")
If line.Length <> 0 Then
cmbops.Items.Add(line)
End If
Next line
End If
If File.Exists(root + "\white-list.txt") Then
For Each line As String In File.ReadLines(root + "\white-list.txt")
If line.Length <> 0 Then
cmbwhitelist.Items.Add(line)
End If
Next line
End If
End Sub
Private Sub btnlaunch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnlaunch.Click
If System.IO.Directory.Exists(root + "\setting") = True Then
Else
System.IO.Directory.CreateDirectory(root + "\setting")
End If
Dim sbcmbworld As New StringBuilder()
For Each item As Object In cmbworld.Items
sbcmbworld.AppendFormat("{0} {1}", item, Environment.NewLine)
Next
Dim cmbworldsave As String = root + "\setting\world.txt"
If System.IO.File.Exists(cmbworldsave) = True Then
Else
System.IO.File.Create(root + "\setting\world.txt").Dispose()
End If
Dim worldWriter As New System.IO.StreamWriter(cmbworldsave)
worldWriter.Write(sbcmbworld.ToString()) 'Use the stringbuilder here
worldWriter.WriteLine()
worldWriter.Close()
Dim sbcmbip As New StringBuilder()
For Each item As Object In cmbworld.Items
sbcmbip.AppendFormat("{0} {1}", item, Environment.NewLine)
Next
Dim cmbipsave As String = root + "\setting\ip.txt"
If System.IO.File.Exists(cmbworldsave) = True Then
Else
System.IO.File.Create(root + "\setting\ip.txt").Dispose()
End If
Dim ipwriter As New System.IO.StreamWriter(cmbipsave)
ipwriter.Write(sbcmbip.ToString()) 'Use the stringbuilder here
ipwriter.WriteLine()
ipwriter.Close()
Dim sbcmblevelseed As New StringBuilder()
For Each item As Object In cmbworld.Items
sbcmbip.AppendFormat("{0} {1}", item, Environment.NewLine)
Next
Dim cmblevelseedsave As String = root + "\setting\levelseed.txt"
If System.IO.File.Exists(cmbworldsave) = True Then
Else
System.IO.File.Create(root + "\setting\levelseed.txt").Dispose()
End If
Dim levelseedWriter As New System.IO.StreamWriter(cmbipsave)
levelseedWriter.Write(sbcmblevelseed.ToString()) 'Use the stringbuilder here
levelseedWriter.WriteLine()
levelseedWriter.Close()
Dim sbcmbbannedplayers As New StringBuilder()
For Each item As Object In cmbbannedplayers.Items
sbcmbbannedplayers.AppendFormat("{0} {1}", item, Environment.NewLine)
Dim cmbbannedplayerssave As String = root + "\banned-players.txt"
If System.IO.File.Exists(cmbbannedplayerssave) = True Then
Else
System.IO.File.Create(cmbbannedplayerssave).Dispose()
End If
Dim bannedplayersWriter As New System.IO.StreamWriter(cmbbannedplayerssave)
bannedplayersWriter.Write(sbcmbbannedplayers.ToString()) 'Use the stringbuilder here
bannedplayersWriter.WriteLine()
bannedplayersWriter.Close()
Next
Dim sbcmbbannedips As New StringBuilder()
For Each item As Object In cmbbannedips.Items
sbcmbbannedips.AppendFormat("{0} {1}", item, Environment.NewLine)
Dim cmbbannedipssave As String = root + "\banned-ips.txt"
If System.IO.File.Exists(cmbbannedipssave) = True Then
Else
System.IO.File.Create(cmbbannedipssave).Dispose()
End If
Dim bannedipsWriter As New System.IO.StreamWriter(cmbbannedipssave)
bannedipsWriter.Write(sbcmbbannedips.ToString()) 'Use the stringbuilder here
bannedipsWriter.WriteLine()
bannedipsWriter.Close()
Next
Dim sbcmbops As New StringBuilder()
For Each item As Object In cmbops.Items
sbcmbops.AppendFormat("{0} {1}", item, Environment.NewLine)
Dim cmbopssave As String = root + "\ops.txt"
If System.IO.File.Exists(cmbopssave) = True Then
Else
System.IO.File.Create(cmbopssave).Dispose()
End If
Dim opsWriter As New System.IO.StreamWriter(cmbopssave)
opsWriter.Write(sbcmbops.ToString()) 'Use the stringbuilder here
opsWriter.WriteLine()
opsWriter.Close()
Next
Dim sbcmbwhitelist As New StringBuilder()
For Each item As Object In cmbwhitelist.Items
sbcmbwhitelist.AppendFormat("{0} {1}", item, Environment.NewLine)
Dim cmbwhitelistsave As String = root + "\white-list.txt"
If System.IO.File.Exists(cmbwhitelistsave) = True Then
Else
System.IO.File.Create(cmbwhitelistsave).Dispose()
End If
Dim whitelistWriter As New System.IO.StreamWriter(cmbwhitelistsave)
whitelistWriter.Write(sbcmbwhitelist.ToString()) 'Use the stringbuilder here
whitelistWriter.WriteLine()
whitelistWriter.Close()
Next
If System.IO.File.Exists(root + "\server.properties") = True Then
Else
System.IO.File.Create(root + "\server.properties").Dispose()
End If
If cmbip.Text = "Lan" Then
cmbip.Text = ""
End If
If cmblevelseed.Text = "None" Then
cmblevelseed.Text = ""
End If
Dim propertyWriter As New System.IO.StreamWriter(root + "\server.properties")
propertyWriter.Write("#ServerCraft, Created By Bradley Smithies - Kuzon")
propertyWriter.WriteLine("")
propertyWriter.Write("#Minecraft server properties")
propertyWriter.WriteLine("")
propertyWriter.Write("#Created: " + DateTime.Now.ToLongDateString + " at " + DateTime.Now.ToLongTimeString)
propertyWriter.WriteLine("")
propertyWriter.WriteLine("")
propertyWriter.Write("level-name=" + cmbworld.Text)
propertyWriter.WriteLine("")
propertyWriter.Write("allow-nether=" + allownether)
propertyWriter.WriteLine("")
propertyWriter.Write("view-distance=" + nudviewdistance.Text)
propertyWriter.WriteLine("")
propertyWriter.Write("spawn-monsters=" + spawnmonsters)
propertyWriter.WriteLine("")
propertyWriter.Write("online-mode=" + onlinemode)
propertyWriter.WriteLine("")
propertyWriter.Write("spawn-monsters=" + spawnmonsters)
propertyWriter.WriteLine("")
propertyWriter.Write("max-players=" + nudmaxplayers.Text)
propertyWriter.WriteLine("")
propertyWriter.Write("server-ip=" + cmbip.Text)
propertyWriter.WriteLine("")
propertyWriter.Write("pvp=" + pvp)
propertyWriter.WriteLine("")
propertyWriter.Write("level-seed=" + cmblevelseed.Text)
propertyWriter.WriteLine("")
propertyWriter.Write("server-port=" + txbseverport.Text)
propertyWriter.WriteLine("")
propertyWriter.Write("allow-flight=" + allowflight)
propertyWriter.WriteLine("")
propertyWriter.Write("white-list=" + whitelist)
propertyWriter.WriteLine("")
propertyWriter.Close()
If cmbip.Text = "" Then
cmbip.Text = "Lan"
End If
If cmblevelseed.Text = "" Then
cmblevelseed.Text = "None"
End If
If cbxlaunch.Checked Then
Dim serverpath As String
If cmbserverapplication.Text = "Jar Server" Then
If System.IO.File.Exists(serverfile) = True Then
If Environment.Is64BitOperatingSystem = True Then
bit = "64"
Else
bit = "32"
End If
Dim javapath As String
Dim launchcode As String
If bit = 64 Then
If System.IO.File.Exists("C:\Program Files (x86)\Java\jre7\bin\java.exe") = True Then
javapath = "C:\Program Files (x86)\Java\jre7\bin\java.exe"
Else
javapath = "C:\Program Files (x86)\Java\jre6\bin\java.exe"
End If
Else
If System.IO.File.Exists("C:\Program Files\Java\jre7\bin\java.exe") = True Then
javapath = "C:\Program Files\Java\jre7\bin\java.exe"
Else
javapath = "C:\Program Files\Java\jre6\bin\java.exe"
End If
End If
launchcode = "-Xmx" + nudram.Value + "M -Xms" + nudram.Value + "M -jar " + safeserverfile + " nogui"
' Dim pi As New ProcessStartInfo(javapath)
' pi.Arguments = launchcode
' Process.Start(pi)
Dim jarbatchserver As String = (root + "\runbjarbatchserver.bat")
If System.IO.File.Exists(jarbatchserver) = True Then
Else
System.IO.File.Create(jarbatchserver).Dispose()
End If
Dim jarbatchwriter As New System.IO.StreamWriter(jarbatchserver)
If cbxechooff.Checked = True Then
jarbatchwriter.Write("#ECHO OFF")
jarbatchwriter.WriteLine("")
End If
jarbatchwriter.Write("""" + javapath + """" + " " + launchcode)
jarbatchwriter.WriteLine("")
jarbatchwriter.Write("pause")
jarbatchwriter.WriteLine("")
jarbatchwriter.Close()
System.Diagnostics.Process.Start(jarbatchserver)
Me.Close()
Else
MsgBox("The server file does not exist. Please make sure that you have select the right file type and that it has not been renamed.")
End If
ElseIf cmbserverapplication.Text = "Exe Server" Then
If System.IO.File.Exists(serverfile) = True Then
Dim startInfo As System.Diagnostics.ProcessStartInfo
Dim pStart As New System.Diagnostics.Process
startInfo = New System.Diagnostics.ProcessStartInfo(serverfile)
pStart.StartInfo = startInfo
pStart.Start()
Me.Close()
Else
MsgBox("The server file does not exist. Please make sure that you have select the right file type and that it has not been renamed.")
End If
ElseIf cmbserverapplication.Text = "Bukkit Server" Then
If System.IO.File.Exists(serverfile) = True Then
If Environment.Is64BitOperatingSystem = True Then
bit = "64"
Else
bit = "32"
End If
serverpath = "craftbukkit-0.0.1-SNAPSHOT.jar"
Dim javapath As String
If bit = 64 Then
If System.IO.File.Exists("C:\Program Files (x86)\Java\jre7\bin\java.exe") = True Then
javapath = "C:\Program Files (x86)\Java\jre7\bin\java.exe"
Else
javapath = "C:\Program Files (x86)\Java\jre6\bin\java.exe"
End If
Else
If System.IO.File.Exists("C:\Program Files\Java\jre7\bin\java.exe") = True Then
javapath = "C:\Program Files\Java\jre7\bin\java.exe"
Else
javapath = "C:\Program Files\Java\jre6\bin\java.exe"
End If
End If
Dim bukkitbatchserver As String = (root + "\runbukkitbatchserver.bat")
If System.IO.File.Exists(bukkitbatchserver) = True Then
Else
System.IO.File.Create(bukkitbatchserver).Dispose()
End If
Dim bukkitbatchwriter As New System.IO.StreamWriter(bukkitbatchserver)
If cbxechooff.Checked = True Then
bukkitbatchwriter.Write("#ECHO OFF")
bukkitbatchwriter.WriteLine("")
End If
bukkitbatchwriter.Write("SET BINDIR=%~dp0")
bukkitbatchwriter.WriteLine("")
bukkitbatchwriter.Write("CD /D ""%BINDIR%""")
bukkitbatchwriter.WriteLine("")
bukkitbatchwriter.Write("""" + javapath + """" + " -Xincgc -Xmx1G -jar " + safeserverfile)
bukkitbatchwriter.WriteLine("")
bukkitbatchwriter.Write("pause")
bukkitbatchwriter.Close()
System.Diagnostics.Process.Start(bukkitbatchserver)
Me.Close()
Else
MsgBox("The server file does not exist. Please make sure that you have select the right file type and that it has not been renamed.")
End If
End If
Else
MsgBox("Properties Changed")
End If
End Sub
Private Sub btnaddworld_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnaddworld.Click
If Not cmbworld.Text = "" Then
cmbworld.Items.Add(cmbworld.Text)
cmbworld.Text = ""
End If
For i As Int16 = 0 To Me.cmbworld.Items.Count - 2
For j As Int16 = Me.cmbworld.Items.Count - 1 To i + 1 Step -1
If Me.cmbworld.Items(i).ToString = Me.cmbworld.Items(j).ToString Then
Me.cmbworld.Items.RemoveAt(j)
End If
Next
Next
End Sub
Private Sub btnremoveworld_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnremoveworld.Click
cmbworld.Items.Remove(cmbworld.Text)
cmbworld.Text = ""
End Sub
Private Sub btnaddip_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnaddip.Click
If Not cmbip.Text = "" Then
cmbip.Items.Add(cmbip.Text)
cmbip.Text = ""
End If
For i As Int16 = 0 To Me.cmbip.Items.Count - 2
For j As Int16 = Me.cmbip.Items.Count - 1 To i + 1 Step -1
If Me.cmbip.Items(i).ToString = Me.cmbip.Items(j).ToString Then
Me.cmbip.Items.RemoveAt(j)
End If
Next
Next
End Sub
Private Sub btnremoveip_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnremoveip.Click
If Not cmbip.Text = "Lan" Then
cmbip.Items.Remove(cmbip.Text)
cmbip.Text = ""
End If
End Sub
Private Sub btnaddlevelseed_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnaddlevelseed.Click
If Not cmblevelseed.Text = "" Then
cmblevelseed.Items.Add(cmblevelseed.Text)
cmblevelseed.Text = ""
For i As Int16 = 0 To Me.cmblevelseed.Items.Count - 2
For j As Int16 = Me.cmblevelseed.Items.Count - 1 To i + 1 Step -1
If Me.cmblevelseed.Items(i).ToString = Me.cmblevelseed.Items(j).ToString Then
Me.cmblevelseed.Items.RemoveAt(j)
End If
Next
Next
End If
End Sub
Private Sub btnremovelevelseed_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnremovelevelseed.Click
If Not cmbip.Text = "none" Then
cmblevelseed.Items.Remove(cmblevelseed.Text)
cmblevelseed.Text = ""
End If
End Sub
Private Sub cbxwhitelist_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cbxwhitelist.CheckedChanged
If cbxwhitelist.Checked Then
lblwhitelist.Visible = True
cmbwhitelist.Visible = True
btnaddwhitelist.Visible = True
btnremovewhitelist.Visible = True
Else
lblwhitelist.Visible = False
cmbwhitelist.Visible = False
btnaddwhitelist.Visible = False
btnremovewhitelist.Visible = False
End If
End Sub
Private Sub btnaddbannedplayers_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnaddbannedplayers.Click
If Not cmbbannedplayers.Text = "" Then
cmbbannedplayers.Items.Add(cmbbannedplayers.Text)
cmbbannedplayers.Text = ""
For i As Int16 = 0 To Me.cmbbannedplayers.Items.Count - 2
For j As Int16 = Me.cmbbannedplayers.Items.Count - 1 To i + 1 Step -1
If Me.cmbbannedplayers.Items(i).ToString = Me.cmbbannedplayers.Items(j).ToString Then
Me.cmbbannedplayers.Items.RemoveAt(j)
End If
Next
Next
End If
End Sub
Private Sub btnremovebannedplayers_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnremovebannedplayers.Click
cmbbannedplayers.Items.Remove(cmbbannedplayers.Text)
cmbbannedplayers.Text = ""
End Sub
Private Sub btnaddbannedips_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnaddbannedips.Click
If Not cmbbannedips.Text = "" Then
cmbbannedips.Items.Add(cmbbannedips.Text)
cmbbannedips.Text = ""
For i As Int16 = 0 To Me.cmbbannedips.Items.Count - 2
For j As Int16 = Me.cmbbannedips.Items.Count - 1 To i + 1 Step -1
If Me.cmbbannedips.Items(i).ToString = Me.cmbbannedips.Items(j).ToString Then
Me.cmbbannedips.Items.RemoveAt(j)
End If
Next
Next
End If
End Sub
Private Sub lblremovebannedips_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lblremovebannedips.Click
cmbbannedips.Items.Remove(cmbbannedips.Text)
cmbbannedips.Text = ""
End Sub
Private Sub btnaddops_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnaddops.Click
If Not cmbops.Text = "" Then
cmbops.Items.Add(cmbops.Text)
cmbops.Text = ""
For i As Int16 = 0 To Me.cmbops.Items.Count - 2
For j As Int16 = Me.cmbops.Items.Count - 1 To i + 1 Step -1
If Me.cmbops.Items(i).ToString = Me.cmbops.Items(j).ToString Then
Me.cmbops.Items.RemoveAt(j)
End If
Next
Next
End If
End Sub
Private Sub btnremoveops_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnremoveops.Click
cmbops.Items.Remove(cmbops.Text)
cmbops.Text = ""
End Sub
Private Sub btnaddwhitelist_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnaddwhitelist.Click
If Not cmbwhitelist.Text = "" Then
cmbwhitelist.Items.Add(cmbwhitelist.Text)
cmbwhitelist.Text = ""
For i As Int16 = 0 To Me.cmbwhitelist.Items.Count - 2
For j As Int16 = Me.cmbwhitelist.Items.Count - 1 To i + 1 Step -1
If Me.cmbwhitelist.Items(i).ToString = Me.cmbwhitelist.Items(j).ToString Then
Me.cmbwhitelist.Items.RemoveAt(j)
End If
Next
Next
End If
End Sub
Private Sub btnremovewhitelist_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnremovewhitelist.Click
cmbwhitelist.Items.Remove(cmbwhitelist.Text)
cmbwhitelist.Text = ""
End Sub
Private Sub cmbip_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmbip.SelectedIndexChanged
If cmbip.Text = "Lan" Then
cbxonlinemode.Checked = False
End If
End Sub
Private Sub cbxonlinemode_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cbxonlinemode.CheckedChanged
If cmbip.Text = "Lan" Then
If cbxonlinemode.Checked Then
cbxonlinemode.Checked = False
MsgBox("If you would like to run your server in online mode then please enter an ip other than the Lan option")
End If
End If
End Sub
Private Sub txbroot_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)
cmbbannedplayers.Items.Clear()
cmbip.Items.Clear()
cmbbannedips.Items.Clear()
cmbops.Items.Clear()
If File.Exists(root + "\banned-players.txt") Then
For Each line As String In File.ReadLines(root + "\banned-players.txt")
If line.Length <> 0 Then
cmbbannedplayers.Items.Add(line)
End If
Next line
End If
If File.Exists(root + "\banned-ips.txt") Then
For Each line As String In File.ReadLines(root + "\banned-ips.txt")
If line.Length <> 0 Then
cmbbannedips.Items.Add(line)
End If
Next line
End If
If File.Exists(root + "\ops.txt") Then
For Each line As String In File.ReadLines(root + "\ops.txt")
If line.Length <> 0 Then
cmbops.Items.Add(line)
End If
Next line
End If
If File.Exists(root + "\white-list.txt") Then
For Each line As String In File.ReadLines(root + "\white-list.txt")
If line.Length <> 0 Then
cmbwhitelist.Items.Add(line)
End If
Next line
End If
End Sub
Private Sub btnserverfilebrowse_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnserverfilebrowse.Click
Dim ofdserverfile As New OpenFileDialog
'Dialog
With ofdserverfile
.Title = "Please Select Server File"
' Desktop is the root folder in the dialog.
.InitialDirectory = root
.Filter = filter
' Prompt the user with a custom message.
root = .FileName
If .ShowDialog = DialogResult.OK Then
serverfile = .FileName
safeserverfile = .SafeFileName
txbserverfile.Text = serverfile
root = Path.GetDirectoryName(serverfile)
End If
End With
End Sub
Private Sub cmbserverapplication_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmbserverapplication.SelectedIndexChanged
If cmbserverapplication.Text = "Exe Server" Then
serverapplication = "minecraft_server.exe"
lblram.Visible = False
nudram.Visible = False
filter = "Exe Server|*.exe|All Files|*.*"
ElseIf cmbserverapplication.Text = "Jar Server" Then
serverapplication = "minecraft_server.jar"
lblram.Visible = True
nudram.Visible = True
filter = "Jar Server|*.jar|All Files|*.*"
ElseIf cmbserverapplication.Text = "Bukkit Server" Then
serverapplication = "craftbukkit-0.0.1-SNAPSHOT.jar"
lblram.Visible = False
nudram.Visible = False
filter = "Bukkit Server|*.jar|All Files|*.*"
End If
Dim CurrrentDirectory As String = CurDir.ToString
If txbserverfile.Text = "" Or txbserverfile.Text = CurDir.ToString + "\minecraft_server.exe" Or txbserverfile.Text = CurDir.ToString + "\minecraft_server.jar" Or txbserverfile.Text = CurDir.ToString + "\craftbukkit-0.0.1-SNAPSHOT.jar" Then
txbserverfile.Text = CurDir.ToString + "\" + serverapplication
End If
End Sub
End Class
instead of
halfram = ((ram / "1,048,576") / "2") - "1"
nudram.Maximum = halfram
If nudram.Value = "" Or "1024" Then
nudram.Value = halfram
End If
code
halfram = ((ram / 1048576) / 2) - 1
nudram.Maximum = halfram
If nudram.Value = 0 Or nudram.Value = 1024 Then
nudram.Value = halfram
End If
But for your own sake set the option strict to ON so you declare your variables. Think of the poor guy that has to edit your source in 10 years time.
try If nudram.Value = 0 Or nudram.Value = 1024 Then
You could try changing "1,048,576" to "1.048.576" or use it as a number instead, just 1048576.
The decimal/thousand separator can be different on different systems, and some will interpret 1,048,576 as a million and change (, as thousand separator), while other will try to interpret as double (and blow up on the second decimal separator).
If bit = 64 should be If bit = "64"