I have a problem with DropDownList's SelectedIndexChanged event.
when the value of district DropDownList is changed, it fires its SelectedIndexChanged event but it does not fill the licencee DropDownList.
Also, when the value of dynamically created brandDropDownList is changed, it first fires the SelectedIndexChanged event of district DropDownList and then fills the licencee DropDownList.
I am giving some code here so you can understand what I am saying.
Imports System.Data
Imports System.Data.SqlClient
Imports Microsoft.VisualBasic.CompilerServices
Partial Class Transaction_Sales_Demand
Inherits System.Web.UI.Page
Dim objClsDemand As New ClsDemand
Dim objClsPurchase As New ClsPurchaseOrderGen
Shared ds As DataSet
Shared dt As DataTable
Public WithEvents Drpdynamic As DropDownList
Public WithEvents Txtdynamic As TextBox
Public unitname() As String
Protected Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init
'If Not IsPostBack Then
'ds = objClsDemand.FillUnitInHeader()
'generateDynamicColumns(ds)
'GrdDemand.DataBind()
'End If
End Sub
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
''Dim newddlBrand As DropDownList
'Dim strddlbrandID As String
'Dim ddlNewBrand As DropDownList = form1.FindControl("ddlBrand")
'strddlbrandID = ddlNewBrand.ID
ds = objClsDemand.FillUnitInHeader()
generateDynamicColumns(ds)
If Not (IsPostBack) Then
'objClsDemand.FillBrand(ddlNewBrand)
objClsDemand.FillDistrict(ddlDistrict)
End If
End Sub
Private Sub generateDynamicColumns(ByVal Ds As DataSet)
Dim i As Integer = 0
Dim h As Integer = 0
Dim pnl As Panel = New Panel()
Dim intcount As Integer = 0
' Dim dr As DataRow
'objClsDemand.FillLicencee(ddllicencee)
'objClsDemand.FillBrand(ddlBrand)
'objClsDemand.FillLabel(ddlLabel)
pnl.Controls.Clear()
dt = New DataTable()
If dt.Columns.Count = 0 Then
dt.Columns.Add("LabelCode")
dt.Columns.Add("BrandName")
dt.Columns.Add("LabelName")
dt.Columns.Add("ProofLiter")
End If
For i = 0 To Ds.Tables(0).Rows.Count - 1
dt.Columns.Add(New DataColumn(Ds.Tables(0).Rows(i)(0)))
dt.Columns.Add(New DataColumn(Ds.Tables(0).Rows(i)(1)))
Next
Dim Lbldynamic As Label
Response.Write("</table>")
Response.Write("<tr>")
For intcount = 0 To dt.Columns.Count - 1
Response.Write("<th>")
Response.Write("<b>")
Lbldynamic = New Label()
Lbldynamic.Height = "23"
Lbldynamic.Font.Bold = True
Lbldynamic.Style("Position") = "Absolute"
' txtunit(i).Style("Top") = "210px"
Lbldynamic.Style("Top") = 130
If dt.Columns(intcount).ColumnName = "BrandName" Then
Lbldynamic.Width = "140"
Lbldynamic.Style("Left") = h
h = h + 143
ElseIf dt.Columns(intcount).ColumnName = "LabelName" Then
Lbldynamic.Width = "210"
Lbldynamic.Style("Left") = h
h = h + 213
Else
Lbldynamic.Width = "110"
Lbldynamic.Style("Left") = h
h = h + 113
End If
Lbldynamic.Text = dt.Columns(intcount).ColumnName
'unitname(intcount) = Lbldynamic.Text
' Response.Write(un.GetValue(i))
Response.Write("</b>")
Response.Write("</th>")
pnl.Controls.Add(Lbldynamic)
'form1.Controls.Add(Lbldynamic)
Response.Write("<th>")
Next
Response.Write("</tr>")
h = 0
Response.Write("<tr>")
For intcount = 0 To dt.Columns.Count - 1
If dt.Columns(intcount).ColumnName = "BrandName" Or dt.Columns(intcount).ColumnName = "LabelName" Then
Response.Write("<th>")
Response.Write("<b>")
Drpdynamic = New DropDownList
If dt.Columns(intcount).ColumnName = "BrandName" Then
Drpdynamic.ID = "ddlBrand"
Drpdynamic.AutoPostBack = True
objClsDemand.FillBrand(Drpdynamic)
AddHandler Drpdynamic.SelectedIndexChanged, AddressOf Me.Drpdynamic_SelectedIndexChanged
Drpdynamic.Width = "140"
Drpdynamic.Style("Left") = h
h = h + 143
ElseIf dt.Columns(intcount).ColumnName = "LabelName" Then
Drpdynamic.ID = "ddlLabel"
Drpdynamic.AutoPostBack = True
Drpdynamic.Width = "210"
Drpdynamic.Style("Left") = h
h = h + 213
End If
Drpdynamic.Height = "23"
'Drpdynamic.Width = "110"
Drpdynamic.Font.Bold = True
Drpdynamic.Style("Position") = "Absolute"
' txtunit(i).Style("Top") = "210px"
Drpdynamic.Style("Top") = 150
'Drpdynamic.Style("Left") = h
' Response.Write(un.GetValue(i))
Response.Write("</b>")
Response.Write("</th>")
pnl.Controls.Add(Drpdynamic)
'h = h + 113
Response.Write("<th>")
Else
Response.Write("<th>")
Response.Write("<b>")
Txtdynamic = New TextBox()
If dt.Columns(intcount).ColumnName = "LabelCode" Then
Txtdynamic.ID = "txtLabelCode"
Else
Txtdynamic.ID = "txtdynamic" + intcount.ToString()
End If
AddHandler Txtdynamic.TextChanged, AddressOf Me.TextBox_TextChanged
Txtdynamic.AutoPostBack = True
Txtdynamic.Height = "23"
Txtdynamic.Width = "110"
Txtdynamic.Font.Bold = True
Txtdynamic.Style("Position") = "Absolute"
' txtunit(i).Style("Top") = "210px"
Txtdynamic.Style("Top") = 150
Txtdynamic.Style("Left") = h
' Response.Write(un.GetValue(i))
Response.Write("</b>")
Response.Write("</th>")
pnl.Controls.Add(Txtdynamic)
h = h + 113
Response.Write("<th>")
End If
Next
Response.Write("</tr>")
Response.Write("</table>")
form1.Controls.Add(pnl)
End Sub
Private Sub Drpdynamic_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Drpdynamic.SelectedIndexChanged
Try
Dim ddlNewBrand As DropDownList = New DropDownList()
ddlNewBrand = DirectCast(sender, DropDownList)
Dim ddlNewLabel As DropDownList = New DropDownList()
ddlNewLabel = form1.FindControl("ddlLabel")
If Not ddlNewBrand.SelectedValue = "" Then
objClsDemand.BrandId = ddlNewBrand.SelectedValue
End If
objClsDemand.FillLabel(ddlNewLabel)
'ddlLabel.Enabled = True
Catch ex As Exception
ProjectData.SetProjectError(ex)
clsFunctions.ErrorLog(DateAndTime.Today, "Transaction", "Demand Generation", "ddlBrand_SelectedIndexChanged", ex.Message)
ProjectData.ClearProjectError()
End Try
End Sub
Private Sub TextBox_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Txtdynamic.TextChanged
Dim txtNewText As TextBox = New TextBox()
txtNewText = DirectCast(sender, TextBox)
Dim i As Integer = 3
Dim ddlNewBrand As DropDownList = DirectCast(sender, TextBox).FindControl("ddlBrand")
Dim ddlNewLabel As DropDownList = New DropDownList()
ddlNewLabel = form1.FindControl("ddlLabel")
If txtNewText.ID = "txtLabelCode" Then
Try
Dim dr As DataRow
objClsPurchase.LabelCode = txtNewText.Text
If Not txtNewText.Text.Equals("") Then
dr = objClsPurchase.fillDetails()
If Not IsDBNull(dr("Brandname")) Then
ddlNewBrand.SelectedItem.Text = dr("BrandName")
ddlNewBrand.Enabled = False
End If
If Not IsDBNull(dr("LabelName")) Then
If ddlNewLabel.SelectedValue = "" Then
objClsDemand.FillLabel(ddlNewLabel)
ddlNewLabel.SelectedItem.Text = dr("LabelName")
ddlNewLabel.Enabled = False
Else
ddlNewLabel.SelectedItem.Text = dr("LabelName")
ddlNewLabel.Enabled = False
End If
End If
Else
objClsPurchase.FillBrand(ddlNewBrand)
End If
Catch ex As Exception
ProjectData.SetProjectError(ex)
clsFunctions.ErrorLog(DateAndTime.Today, "Transaction", "Purchase Order Generation", "txtLabelcode_TextChanged", ex.Message)
ProjectData.ClearProjectError()
End Try
'Else
' Dim dr1 As DataRow
' For i = 4 To dt.Columns.Count - 1
' If txtNewText.ID = "txtdynamic" + i.ToString() Then
' Dim txtnew As TextBox = New TextBox()
' txtnew = form1.FindControl(dt.Columns(i + 1).ColumnName())
' txtNewText.ID = "txtdynamic" + i.ToString()
' objClsDemand.UnitId = objClsDemand.UnitId_byName(dt.Columns(i).ColumnName)
' objClsDemand.LabelId = Val(ddlNewLabel.SelectedValue)
' dr1 = objClsDemand.FillRate(txtNewText)
' txtnew.Text = dr1("LendingPrice")
' End If
' Next
End If
End Sub
Protected Sub ImageButton3_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles ImageButton3.Click
'Dim txtNew As TextBox = New TextBox()
'Dim ddlnew As DropDownList = New DropDownList()
'Dim str As String
'For intcount = 0 To dt.Columns.Count - 1
' If dt.Columns(intcount).ColumnName = "BrandName" Then
' 'ddlnew = DirectCast(sender, DropDownList)
' ddlnew = form1.FindControl("ddlBrand")
' MsgBox("this is Brand ddl" + ddlnew.SelectedItem.Text)
' ElseIf dt.Columns(intcount).ColumnName = "LabelName" Then
' 'ddlnew = DirectCast(sender, DropDownList)
' ddlnew = form1.FindControl("ddlLabel")
' MsgBox("this is label ddl" + ddlnew.SelectedItem.Text)
' ElseIf dt.Columns(intcount).ColumnName = "LabelCode" Then
' 'txtNew = DirectCast(sender, TextBox)
' txtNew = form1.FindControl("txtLabelCode")
' MsgBox("this is label code txt")
' Else
' str = "txtdynamic" + intcount.ToString()
' MsgBox("this is" + str + " label code txt" + txtNew.Text)
' End If
'Next
End Sub
Protected Sub ddlDistrict_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlDistrict.SelectedIndexChanged
If Not ddlDistrict.SelectedValue = "" Then
objClsDemand.DistrictId = ddlDistrict.SelectedValue
End If
objClsDemand.FillLicencee(ddllicencee)
End Sub
End Class
Have you checked that after you set a new datasource for each dropdown you are making a call to DataBind() on that contol?
Related
I am working with Vb.NET and the requirement was to find the string n RTF control and make it , bold,italic or whatever color,I have done my efforts to find the string but yesterday I found it not working as per my requirement.
At bottom I will write the full code with test data.
I have a simple form and two control on it, One is CombBox to Select Different Test Cases and One RichTextBox for Displaying the Text.
'Class Declarations
Private FormattingApplied As Boolean = False
Private SelectedBold As Boolean = False
Private SearchText As String = String.Empty
Private SelectedItalic As Boolean = False
Private SelectedUnderLine As Boolean = False
' On Form Load
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
cmbList.Items.Add("Apple Pina Apple")
cmbList.Items.Add("Apple Delicious Pineapple")
cmbList.Items.Add("Apple Milk Shake Apa")
cmbList.Items.Add("Apple Strawberry ")
FormattingApplied = True
SelectedBold = True
cmbList.SelectedIndex = 0
End Sub
Function UppercaseFirstLetter(ByVal val As String) As String
' Test for nothing or empty.
If String.IsNullOrEmpty(val) Then
Return val
End If
Dim array() As Char = val.ToCharArray
array(0) = Char.ToUpper(array(0))
Return New String(array)
End Function
Private Sub ApplyFormatting(ByVal SearchText As String)
Dim TrimmedString As String = String.Empty
Dim ISTrimmed As Boolean = False
If FormattingApplied Then
Dim count As New List(Of Integer)()
If rtfText.Text.Length >= 53 Then
rtfText.Text = rtfText.Text.Substring(0, 50) + "..."
End If
For i As Integer = 0 To rtfText.Text.Length - 1
If rtfText.Text.IndexOf(SearchText, i) <> -1 Then
count.Add(rtfText.Text.IndexOf(SearchText, i))
ElseIf rtfText.Text.IndexOf(UppercaseFirstLetter(SearchText), i) <> -1 Then
count.Add(rtfText.Text.IndexOf(UppercaseFirstLetter(SearchText), i))
End If
Next
Try
For i As Integer = 0 To count.Count - 1
rtfText.[Select](count(i), SearchText.Length)
If SelectedBold Then
rtfText.SelectionFont = New Font(rtfText.Font, FontStyle.Bold)
ElseIf SelectedItalic Then
rtfText.SelectionFont = New Font(rtfText.Font, FontStyle.Italic)
ElseIf SelectedUnderLine Then
rtfText.SelectionFont = New Font(rtfText.Font, FontStyle.Underline)
'ElseIf SelectedBold AndAlso SelectedItalic AndAlso SelectedUnderLine Then
' rtfText.SelectionFont = New Font(rtfText.Font, FontStyle.Underline)
End If
count.RemoveAt(i)
Next
'For i As Integer = 0 To count.Count - 1
' rtfText.[Select](count(i), SearchText.Length)
' If SelectedBold Then
' rtfText.SelectionFont = New Font(rtfText.Font, FontStyle.Bold)
' ElseIf SelectedItalic Then
' rtfText.SelectionFont = New Font(rtfText.Font, FontStyle.Italic)
' ElseIf SelectedUnderLine Then
' rtfText.SelectionFont = New Font(rtfText.Font, FontStyle.Underline)
' End If
' count.RemoveAt(i)
'Next
Catch
count.Reverse()
End Try
rtfText.[Select](rtfText.Text.Length, 0)
rtfText.SelectionFont = New Font(rtfText.Font, FontStyle.Regular)
End If
End Sub
Private Sub cmbList_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmbList.SelectedIndexChanged
rtfText.Text = cmbList.SelectedItem.ToString()
rtfText.[Select](0, rtfText.Text.Length)
rtfText.SelectionFont = New Font(rtfText.Font, FontStyle.Regular)
If cmbList.SelectedIndex > -1 Then
ApplyFormatting("apple")
End If
End Sub
Here is the output:
Use this method
Private Sub formatString(ByVal SearchText As String)
Dim position As Integer = 0
Dim rtfString As String = LCase(rtfText.Text)
Dim cnt As Integer = 0
Dim isStop As Boolean = False
While Not isStop
Dim i As Integer = rtfString.IndexOf(SearchText, cnt)
If i < 0 Then
isStop = True
Else
rtfText.Select(i, SearchText.Length)
rtfText.SelectionFont = New Font(rtfText.Font, FontStyle.Bold)
cnt = i + 1
End If
End While
rtfText.Select(position, 0)
End Sub
in the cmbList_SelectedIndexChanged
If cmbList.SelectedIndex > -1 Then
'ApplyFormatting("apple")
formatString("apple")
End If
I have a code that makes small boxes at the side of the screen that when the mouse hovers over it, it grows and displays information in the label. How could I do this? Currently, the form does not register the label.
This is the button to make the form and the label.
Private Sub MakeForm()
Dim number As Integer = 1
Dim xaxis As Integer = 0
Dim yaxis As Integer = 0
Dim formlist As New List(Of Form)
Dim index As Integer = 0
For Each x In lstDate.Items
Dim frm As New Form
frm.Name = "frm" & number
frm.Text = "New Form"
frm.StartPosition = FormStartPosition.Manual
frm.FormBorderStyle = Windows.Forms.FormBorderStyle.None
frm.TopMost = True
frm.Opacity = 0.4
Dim lbl As New Label
lbl.Text = x & vbNewLine & lstAssignments.Items.Item(index) & vbNewLine & lstAN.Items.Item(index)
lbl.ForeColor = Color.White
frm.Controls.Add(lbl)
lbl.Hide()
AddHandler frm.MouseEnter, AddressOf frm_MouseEnter
AddHandler frm.MouseLeave, AddressOf frm_MouseLeave
If DateDiff(DateInterval.Day, Now(), x) <= 1 Then
frm.BackColor = Color.Red
Else
frm.BackColor = Color.Black
End If
frm.AllowTransparency = True
formlist.Add(frm)
frm.Show()
number += 1
frm.Size = New Size(20, 50)
frm.Location = New Point(My.Computer.Screen.Bounds.Size.Width - frm.Width, yaxis)
yaxis += frm.Height + 10
index += 1
Next
End Sub
This is the code for mouse entry
Private Sub frm_MouseEnter(ByVal sender As System.Object, ByVal e As EventArgs)
Dim frm1 As Form = DirectCast(sender, Form)
Dim lbl As Label = New Label
lbl.Show()
frm1.Opacity = 1
frm1.BringToFront()
frm1.Size = New Size(200, 100)
Dim test As Integer = 1
Dim counter As Integer = 0
Dim yaxis As Integer = 0
Dim fin As Boolean = False
Do Until fin = True
If frm1.Name = "frm" & test Then
yaxis = counter
fin = True
Else
counter += 60
test += 1
End If
Loop
frm1.Location = New Point(My.Computer.Screen.Bounds.Size.Width - frm1.Width, yaxis)
End Sub
This is the code for mouse leave
Private Sub frm_MouseLeave(ByVal sender As System.Object, ByVal e As EventArgs)
Dim frm1 As Form = DirectCast(sender, Form)
frm1.Opacity = 0.4
frm1.BringToFront()
frm1.Size = New Size(20, 50)
Dim test As Integer = 1
Dim counter As Integer = 0
Dim yaxis As Integer = 0
Dim fin As Boolean = False
Do Until fin = True
If frm1.Name = "frm" & test Then
yaxis = counter
fin = True
Else
counter += 10 + frm1.Height
test += 1
End If
Loop
frm1.Location = New Point(My.Computer.Screen.Bounds.Size.Width - frm1.Width, yaxis)
End Sub
Thanks!
I have the below code and and I want to create a PDF using iTextSharp.
How do I do that without creating a database (because the code for every row in the datagridview is different)?
Option Strict On
Option Explicit On
Public Class Form1
Dim counter As Integer
Dim Total As String
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
Dim List = New List(Of Test)
Try
'
' Fill in the data grid with a List
'
'
' code for First Row
'
Dim Bonus = (CDbl(ComboBox2.SelectedItem) * CDbl(TextBox2.Text) * 0.001)
Dim SumAssured = TextBox2.Text
Dim NormalCover = CDbl(TextBox2.Text) + Bonus
Dim DAB = (CDbl(CStr(TextBox2.Text)) * 2)
Dim Premium = TextBox4.Text
Dim Tax = (CDbl(TextBox4.Text) * CDec(ComboBox1.SelectedItem) * 0.01)
Dim Net_outgo = CDbl(CDbl(TextBox4.Text) - Tax)
Dim AccBenefit = DAB + Bonus
Dim Return_From_LIC = CStr(0)
List.Add(New Test(TextBox1.Text, CStr(NormalCover), CStr(AccBenefit), Premium, CStr(Tax), CStr(Net_outgo), CStr(Return_From_LIC)))
'
' code for Second to second Last Row
'
For Me.counter = 0 To CInt((CDbl(TextBox3.Text) - 2))
TextBox1.Text = CStr(CDbl(TextBox1.Text) + 1)
NormalCover = CDbl(CStr(NormalCover + Bonus))
AccBenefit = CDbl(CStr(AccBenefit + Bonus))
Premium = TextBox4.Text
Tax = CDbl(TextBox4.Text) * CDec(ComboBox1.SelectedItem) * 0.01
Net_outgo = CDbl(CDbl(TextBox4.Text) - Tax)
Return_From_LIC = CStr(0)
List.Add(New Test(TextBox1.Text, CStr(NormalCover), CStr(AccBenefit), Premium, CStr(Tax), CStr(Net_outgo), CStr(Return_From_LIC)))
Next
'
' Code of Last column
'
TextBox1.Text = CStr(CDbl(TextBox1.Text) + 1)
NormalCover = CDbl(CStr(NormalCover + Bonus))
AccBenefit = CDbl(CStr(AccBenefit + Bonus))
Premium = CStr(0)
Tax = CDbl(CStr(0))
Net_outgo = CDbl(CStr(0))
Return_From_LIC = CStr(CDbl(TextBox2.Text) + Bonus * CDbl(TextBox3.Text))
List.Add(New Test(TextBox1.Text, CStr(NormalCover), CStr(AccBenefit), Premium, CStr(Tax), CStr(Net_outgo), CStr(Return_From_LIC)))
'
' Code of Summary column
'
TextBox1.Text = "Total"
NormalCover = Nothing
AccBenefit = Nothing
Premium = CStr(CDbl(TextBox4.Text) * CDbl(TextBox3.Text))
Tax = CDbl(TextBox4.Text) * CDec(ComboBox1.SelectedItem) * 0.01 * CDbl(TextBox3.Text)
Net_outgo = CDbl(CDbl(CDbl(TextBox4.Text) - (CDbl(TextBox4.Text) * CDec(ComboBox1.SelectedItem) * 0.01)) * CDbl(TextBox3.Text))
Return_From_LIC = CStr("-")
List.Add(New Test(TextBox1.Text, CStr(NormalCover), CStr(AccBenefit), Premium, CStr(Tax), CStr(Net_outgo), CStr(Return_From_LIC)))
DataGridView1.DataSource = List
TextBox1.Text = Nothing
TextBox2.Text = Nothing
TextBox3.Text = Nothing
TextBox4.Text = Nothing
ComboBox1.SelectedItem = Nothing
ComboBox2.SelectedItem = Nothing
Catch ex As Exception
MsgBox("Check Your Input Values")
End Try
End Sub
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
'
' Fill in the data grid on form load.
'
Me.DataGridView1.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells
End Sub
End Class
''' <summary>
''' This class contains Seven properties.
''' </summary>
Public Class Test
Public Sub New(ByVal Age As String, ByVal Normal_Risk_Cover As String, _
ByVal Accidental_Risk_Cover As String, ByVal Annual_Premium As String, _
ByVal Tax_Rebate As String, ByVal Net_Outgo As String, ByVal Return_From_LIC As String)
_Age = Age
_Normal_Risk_Cover = Normal_Risk_Cover
_Accidental_Risk_Cover = Accidental_Risk_Cover
_Annual_Premium = Annual_Premium
_Tax_Rebate = Tax_Rebate
_Net_Outgo = Net_Outgo
_Return_From_LIC = Return_From_LIC
End Sub
Private _Age As String
Public Property Age() As String
Get
Return _Age
End Get
Set(ByVal value As String)
_Age = value
End Set
End Property
Private _Normal_Risk_Cover As String
Public Property Normal_Risk_Cover() As String
Get
Return _Normal_Risk_Cover
End Get
Set(ByVal value As String)
_Normal_Risk_Cover = value
End Set
End Property
Private _Accidental_Risk_Cover As String
Public Property Accidental_Risk_Cover() As String
Get
Return _Accidental_Risk_Cover
End Get
Set(ByVal value As String)
_Accidental_Risk_Cover = value
End Set
End Property
Private _Annual_Premium As String
Public Property Annual_Premium() As String
Get
Return _Annual_Premium
End Get
Set(ByVal value As String)
_Annual_Premium = value
End Set
End Property
Private _Tax_Rebate As String
Public Property Tax_Rebate() As String
Get
Return _Tax_Rebate
End Get
Set(ByVal value As String)
_Tax_Rebate = value
End Set
End Property
Private _Net_Outgo As String
Public Property Net_Outgo() As String
Get
Return _Net_Outgo
End Get
Set(ByVal value As String)
_Net_Outgo = value
End Set
End Property
Private _Return_From_LIC As String
Public Property Return_From_LIC() As String
Get
Return _Return_From_LIC
End Get
Set(ByVal value As String)
_Return_From_LIC = value
End Set
End Property
End Class
I could able to sort out my problem I make little changes in my codes and now without creating database I could create pdf file for others to know I am submitting my codes below for others to study and for more improvements if needed
Option Strict On
Option Explicit On
Imports System
Imports iTextSharp.text
Imports iTextSharp.text.pdf
Imports System.IO
Public Class Form1
Dim dsPeople As New DataSet("People")
Dim dt As New DataTable
Dim counter As Integer
Dim Total As String
Dim TrueTypeFont As Object
Private Sub Button1_Click(sender As System.Object, e As
System.EventArgs) Handles Button1.Click
Try
'
' code for First Row
'
Dim Bonus = (CDbl(ComboBox2.SelectedItem) * CDbl(TextBox2.Text) *
0.001)
Dim SumAssured = TextBox2.Text
Dim NormalCover = CDbl(TextBox2.Text) + Bonus
Dim DAB = (CDbl(CStr(TextBox2.Text)) * 2)
Dim Premium = TextBox4.Text
Dim Tax = (CDbl(TextBox4.Text) * CDec(ComboBox1.SelectedItem) *
0.01)
Dim Net_outgo = CDbl(CDbl(TextBox4.Text) - Tax)
Dim AccBenefit = DAB + Bonus
Dim Return_From_LIC = CStr(0)
dt.Rows.Add(New Object() {TextBox1.Text, CStr(NormalCover), CStr
(AccBenefit), Premium, CStr(Tax), CStr(Net_outgo), CStr(Return_From_LIC)})
'
' code for Second to second Last Row
'
For Me.counter = 0 To CInt((CDbl(TextBox3.Text) - 2))
TextBox1.Text = CStr(CDbl(TextBox1.Text) + 1)
NormalCover = CDbl(CStr(NormalCover + Bonus))
AccBenefit = CDbl(CStr(AccBenefit + Bonus))
Premium = TextBox4.Text
Tax = CDbl(TextBox4.Text) * CDec(ComboBox1.SelectedItem) * 0.01
Net_outgo = CDbl(CDbl(TextBox4.Text) - Tax)
Return_From_LIC = CStr(0)
dt.Rows.Add(New Object() {TextBox1.Text, CStr(NormalCover), CStr
(AccBenefit), Premium, CStr(Tax), CStr(Net_outgo), CStr(Return_From_LIC)})
Next
'
' Code of Last column
'
TextBox1.Text = CStr(CDbl(TextBox1.Text) + 1)
NormalCover = CDbl(CStr(NormalCover + Bonus))
AccBenefit = CDbl(CStr(AccBenefit + Bonus))
Premium = CStr(0)
Tax = CDbl(CStr(0))
Net_outgo = CDbl(CStr(0))
Return_From_LIC = CStr(CDbl(TextBox2.Text) + Bonus * CDbl
(TextBox3.Text))
dt.Rows.Add(New Object() {TextBox1.Text, CStr(NormalCover), CStr
(AccBenefit), Premium, CStr(Tax), CStr(Net_outgo), CStr(Return_From_LIC)})
'
' Code of Summary column
'
TextBox1.Text = "Total"
NormalCover = Nothing
AccBenefit = Nothing
Premium = CStr(CDbl(TextBox4.Text) * CDbl(TextBox3.Text))
Tax = CDbl(TextBox4.Text) * CDec(ComboBox1.SelectedItem) * 0.01 *
CDbl(TextBox3.Text)
Net_outgo = CDbl(CDbl(CDbl(TextBox4.Text) - (CDbl(TextBox4.Text)*
CDec(ComboBox1.SelectedItem) * 0.01)) * CDbl(TextBox3.Text))
Return_From_LIC = CStr("-")
dt.Rows.Add(New Object() {TextBox1.Text, CStr(NormalCover), CStr
(AccBenefit), Premium, CStr(Tax), CStr(Net_outgo), CStr(Return_From_LIC)})
DataGridView1.DataSource = dt
TextBox1.Text = Nothing
TextBox2.Text = Nothing
TextBox3.Text = Nothing
TextBox4.Text = Nothing
ComboBox1.SelectedItem = Nothing
ComboBox2.SelectedItem = Nothing
Catch ex As Exception
MsgBox("Check Your Input Values")
End Try
End Sub
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs)
Handles MyBase.Load
'
' Fill in the data grid on form load.
'
'GetCustomers()
dt = dsPeople.Tables.Add("dtPeople")
'create table columns
dt.Columns.Add("Age", GetType(String))
dt.Columns.Add("Natural Cover", GetType(String))
dt.Columns.Add("Accidental Cover", GetType(String))
dt.Columns.Add("Premium", GetType(String))
dt.Columns.Add("Tax Rebate", GetType(String))
dt.Columns.Add("Net Outgo", GetType(String))
dt.Columns.Add("Return From LIC", GetType(String))
Me.DataGridView1.AutoSizeColumnsMode =
DataGridViewAutoSizeColumnsMode.AllCells
End Sub
Private Sub Button2_Click(sender As System.Object, e As System.EventArgs)
Handles Button2.Click
Dim bHasErrors As Boolean = False
Dim ErrorMessage As String = ""
Dim FileName As String = System.IO.Path.Combine
(AppDomain.CurrentDomain.BaseDirectory, "Customers.pdf")
Dim Document As Document = New
Document '(iTextSharp.text.PageSize.LETTER, 50, 10, 10, 10)
Try
PdfWriter.GetInstance(Document, New System.IO.FileStream(FileName,
System.IO.FileMode.Create))
Document.Open()
Document.NewPage()
Document.Add(New Paragraph("Hello World", FontFactory.GetFont
("Arial", 20, BaseColor.BLACK)))
Dim ch As New Chunk("Your Policy Presentation ", FontFactory.GetFont
("Arial", 15, BaseColor.BLACK))
Document.Add(ch)
Dim aTable As PdfPTable
aTable = New PdfPTable(dt.Columns.Count)
For Each col As DataColumn In dt.Columns
aTable.AddCell(col.ColumnName)
Next
Document.Add(aTable)
For Each row As DataRow In dt.Rows
aTable = New PdfPTable(dt.Columns.Count)
aTable.AddCell(row.Field(Of String)("Age"))
aTable.AddCell(row.Field(Of String)("Natural Cover"))
aTable.AddCell(row.Field(Of String)("Accidental Cover"))
aTable.AddCell(row.Field(Of String)("Premium"))
aTable.AddCell(row.Field(Of String)("Tax Rebate"))
aTable.AddCell(row.Field(Of String)("Net Outgo"))
aTable.AddCell(row.Field(Of String)("Return From LIC"))
'aTable.AddCell(row.Field(Of String)("Identifier"))
Document.Add(aTable)
Next
Catch de As DocumentException
bHasErrors = True
ErrorMessage = de.Message
Catch ioe As System.IO.IOException
bHasErrors = True
ErrorMessage = ioe.Message
End Try
Document.Close()
If bHasErrors Then
MessageBox.Show("Failed to create document" & Environment.NewLine &
ErrorMessage)
Else
MessageBox.Show("The document" & Environment.NewLine & FileName &
Environment.NewLine & "has been created")
End If
Process.Start(System.IO.Path.Combine
(AppDomain.CurrentDomain.BaseDirectory, "Customers.pdf"))
End Sub
End Class
I have this program that when I typed the same text on the form and to the other form will add one (+1) to the label of my last form..There were no errors but when I wrote the correct answers on the textboxes it just gave me a number 1 instead of 10. Please help me guys. Thanks in advance :)
here is my code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
frm4 = New Form4()
frm1 = New Form1()
Dim Textbox1 As New TextBox
Dim Label3 As New Label
If Textbox1.Text = frm1.TextBox2.Text Then
frm4.Label3.Text = (frm4.Label3.Text) + 1
If TextBox2.Text = frm1.TextBox4.Text Then
frm4.Label3.Text = (frm4.Label3.Text) + 1
If TextBox3.Text = frm1.TextBox6.Text Then
frm4.Label3.Text = (frm4.Label3.Text) + 1
If TextBox4.Text = frm1.TextBox8.Text Then
frm4.Label3.Text = (frm4.Label3.Text) + 1
If TextBox5.Text = frm1.TextBox10.Text Then
frm4.Label3.Text = (frm4.Label3.Text) + 1
If TextBox6.Text = frm1.TextBox12.Text Then
frm4.Label3.Text = (frm4.Label3.Text) + 1
If TextBox7.Text = frm1.TextBox14.Text Then
frm4.Label3.Text = (frm4.Label3.Text) + 1
If TextBox8.Text = frm1.TextBox16.Text Then
frm4.Label3.Text = (frm4.Label3.Text) + 1
If TextBox9.Text = frm1.TextBox18.Text Then
frm4.Label3.Text = (frm4.Label3.Text) + 1
If TextBox10.Text = frm1.TextBox20.Text Then
frm4.Label3.Text = (frm4.Label3.Text) + 1
End If
End If
End If
End If
End If
End If
End If
End If
End If
frm4.Show()
Else
frm4.Label3.Text = frm4.Label3.Text
frm4.Show()
End If
End Sub
Form 2 codes:
Public Class Form2
Private frm1 As Form1 ' remove the new here because it creates a new instance of Form1'
Private frm3 As Form3
Public lbl As New Label ' not needed?'
Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.Controls.Add(lbl)
End Sub
Public Sub New(ByVal callerInstance As Form1)
' Call required if you add your constructor manually
InitializeComponent()
' save the instance of the Me variable passed to this constructor
frm1 = callerInstance
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
' Dim Label21 As Label = New Label ' this label is not needed'
' Dim Textbox1 As TextBox = New TextBox ' this textbox is not needed'
' Create a new instance of Form3, do not use the automatic Form3 instance
' automatically created by VB.NET
frm3 = New Form3()
' now you are referring to the caller instance of Form1 '
' where there is the textbox filled with your text '
frm3.Label21.Text = frm1.TextBox1.Text
frm3.Label22.Text = frm1.TextBox3.Text
frm3.Label23.Text = frm1.TextBox5.Text
frm3.Label24.Text = frm1.TextBox7.Text
frm3.Label25.Text = frm1.TextBox9.Text
frm3.Label26.Text = frm1.TextBox11.Text
frm3.Label27.Text = frm1.TextBox13.Text
frm3.Label28.Text = frm1.TextBox15.Text
frm3.Label29.Text = frm1.TextBox17.Text
frm3.Label30.Text = frm1.TextBox19.Text
frm3.Show()
End Sub
End Class
Form1 Codes:
Public Class Form1
Private frm2 As Form2
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
If frm2 Is Nothing Then
frm2 = New Form2(Me)
AddHandler frm2.FormClosed, AddressOf Me.Form2HasBeenClosed
Dim Label21 As Label = New Label
frm2.Label21.Text = TextBox1.Text
frm2.Label21.ForeColor = Color.Black
Dim Label22 As Label = New Label
frm2.Label22.Text = TextBox2.Text
frm2.Label22.ForeColor = Color.Black
Dim Label23 As Label = New Label
frm2.Label23.Text = TextBox3.Text
frm2.Label23.ForeColor = Color.Black
Dim Label24 As Label = New Label
frm2.Label24.Text = TextBox4.Text
frm2.Label24.ForeColor = Color.Black
Dim Label25 As Label = New Label
frm2.Label25.Text = TextBox5.Text
frm2.Label25.ForeColor = Color.Black
Dim Label26 As Label = New Label
frm2.Label26.Text = TextBox6.Text
frm2.Label26.ForeColor = Color.Black
Dim Label27 As Label = New Label
frm2.Label27.Text = TextBox7.Text
frm2.Label27.ForeColor = Color.Black
Dim Label28 As Label = New Label
frm2.Label28.Text = TextBox8.Text
frm2.Label28.ForeColor = Color.Black
Dim Label29 As Label = New Label
frm2.Label29.Text = TextBox9.Text
frm2.Label29.ForeColor = Color.Black
Dim Label30 As Label = New Label
frm2.Label30.Text = TextBox10.Text
frm2.Label30.ForeColor = Color.Black
Dim Label31 As Label = New Label
frm2.Label31.Text = TextBox11.Text
frm2.Label31.ForeColor = Color.Black
Dim Label32 As Label = New Label
frm2.Label32.Text = TextBox12.Text
frm2.Label32.ForeColor = Color.Black
Dim Label33 As Label = New Label
frm2.Label33.Text = TextBox13.Text
frm2.Label33.ForeColor = Color.Black
Dim Label34 As Label = New Label
frm2.Label34.Text = TextBox14.Text
frm2.Label34.ForeColor = Color.Black
Dim Label35 As Label = New Label
frm2.Label35.Text = TextBox15.Text
frm2.Label35.ForeColor = Color.Black
Dim Label36 As Label = New Label
frm2.Label36.Text = TextBox16.Text
frm2.Label36.ForeColor = Color.Black
Dim Label37 As Label = New Label
frm2.Label37.Text = TextBox17.Text
frm2.Label37.ForeColor = Color.Black
Dim Label38 As Label = New Label
frm2.Label38.Text = TextBox18.Text
frm2.Label38.ForeColor = Color.Black
Dim Label39 As Label = New Label
frm2.Label39.Text = TextBox19.Text
frm2.Label39.ForeColor = Color.Black
Dim Label40 As Label = New Label
frm2.Label40.Text = TextBox20.Text
frm2.Label40.ForeColor = Color.Black
End If
If frm2 IsNot Nothing Then
frm2.Show(Me) 'Show Second Form
Me.Hide()
End If
End Sub
Sub Form2HasBeenClosed(ByVal sender As Object, ByVal e As FormClosedEventArgs)
frm2 = Nothing
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
End Class
Form 3 Code:(instance calling to form1)
Public Class Form3
Private frm3 As Form3
Private frm1 As Form1
Private frm4 As Form4
Public Sub New1(ByVal callerInstance As Form1)
' Call required if you add your constructor manually
InitializeComponent()
' save the instance of the Me variable passed to this constructor
frm1 = callerInstance
End Sub
End Class
If you want show in label number of right answers then
You need compare all user answers with right answers
And count times when answers are same:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
frm4 = New Form4()
frm1 = New Form1()
Dim Textbox1 As New TextBox
Dim Label3 As New Label
Dim sameQnt As Int32 = 0
If Textbox1.Text = frm1.TextBox2.Text Then sameQnt += 1
If Textbox2.Text = frm1.TextBox4.Text Then sameQnt += 1
If Textbox3.Text = frm1.TextBox6.Text Then sameQnt += 1
If Textbox4.Text = frm1.TextBox8.Text Then sameQnt += 1
If Textbox5.Text = frm1.TextBox10.Text Then sameQnt += 1
If Textbox6.Text = frm1.TextBox12.Text Then sameQnt += 1
If Textbox7.Text = frm1.TextBox14.Text Then sameQnt += 1
If Textbox8.Text = frm1.TextBox16.Text Then sameQnt += 1
If Textbox9.Text = frm1.TextBox18.Text Then sameQnt += 1
If Textbox10.Text = frm1.TextBox20.Text Then sameQnt += 1
'Print reslut
frm4.Label3.Text = sameQnt.ToString()
frm4.Show()
End Sub
Here is my new answer
Public Class MainForm '<----Your main form class name
Dim frm4 = New Form4()'<----declare it here
Dim frm1 = New Form1()'<----declare it here
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim Textbox1 As New TextBox
Dim Label3 As New Label
Dim i As Integer = 0
If Textbox1.Text = frm1.TextBox2.Text Then i += 1 'frm4.Label3.Text = (frm4.Label3.Text) + 1
If TextBox2.Text = frm1.TextBox4.Text Then i += 1 'frm4.Label3.Text = (frm4.Label3.Text) + 1
If TextBox3.Text = frm1.TextBox6.Text Then i += 1 'frm4.Label3.Text = (frm4.Label3.Text) + 1
If TextBox4.Text = frm1.TextBox8.Text Then i += 1 'frm4.Label3.Text = (frm4.Label3.Text) + 1
If TextBox5.Text = frm1.TextBox10.Text Then i += 1 'frm4.Label3.Text = (frm4.Label3.Text) + 1
If TextBox6.Text = frm1.TextBox12.Text Then i += 1 'frm4.Label3.Text = (frm4.Label3.Text) + 1
If TextBox7.Text = frm1.TextBox14.Text Then i += 1 'frm4.Label3.Text = (frm4.Label3.Text) + 1
If TextBox8.Text = frm1.TextBox16.Text Then i += 1 'frm4.Label3.Text = (frm4.Label3.Text) + 1
If TextBox9.Text = frm1.TextBox18.Text Then i += 1 'frm4.Label3.Text = (frm4.Label3.Text) + 1
If TextBox10.Text = frm1.TextBox20.Text Then i += 1 'frm4.Label3.Text = (frm4.Label3.Text) + 1
frm4.Label3.Text = i.ToString()
frm4.Show()
End Sub
End Class
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"