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
Related
I am starting to program in vb.net and I am making a program that takes values from excel columns of 2 files and shows results in a generated excel.
so the first excel has this columns: delivery number, contentID, packages, volume. the second excel has this columns:SPS Number, folder number, contentID, packages, volume.
the excel that i have to generato has this columns:SPS number,folder number, delivery number, contentID,packages, volume. The excel that i have to generate with the program uses contentID as the main identificator, and it has ti compare the packages and volume if the ContentID is the same.
so far i have this in a funtions file:
Module Funciones
'VARIABLES REMATE'
Public ENTREGA As New List(Of String)
Public PAQUETE As New List(Of String)
Public CONTENEDOR As New List(Of String)
Public VOLUMEN As New List(Of String)
'VARIABLES PLANILLA'
Public NSPS As New List(Of String)
Public NPLANILLA As New List(Of String)
Public PAQUETE2 As New List(Of String)
Public IDCONTENEDOR As New List(Of String)
Public VOLUMEN2 As New List(Of String)
Public Sub INICIALIZAR_PLANILLA(ByRef HOJAUSUARIOS As OfficeOpenXml.ExcelWorksheet)
Try
HOJAUSUARIOS.Cells("A1").Value = "N° SPS"
HOJAUSUARIOS.Cells("B1").Value = "N° PLANILLA"
HOJAUSUARIOS.Cells("C1").Value = "ENTREGA"
HOJAUSUARIOS.Cells("D1").Value = "CONTENEDOR"
HOJAUSUARIOS.Cells("E1").Value = "PAQUETES"
HOJAUSUARIOS.Cells("F1").Value = "VOLUMEN"
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Sub
Public Function seleccionardirectorio(ByVal filtro As String) As String
Dim saveFileDialog1 As New SaveFileDialog()
saveFileDialog1.Filter = filtro
saveFileDialog1.Title = "Seleccione Directorio"
saveFileDialog1.ShowDialog()
Return saveFileDialog1.FileName
End Function
Function extraer_valores_remate(ByRef ruta As String) As Boolean
ExcelPackage.LicenseContext = LicenseContext.NonCommercial
Try
Dim stream = System.IO.File.OpenRead(ruta)
Dim package = New OfficeOpenXml.ExcelPackage(stream)
'// Libro
Dim Workbook = package.Workbook
'// Hojas
Dim hojas = Workbook.Worksheets
' Dim aux As Integer = 1
'While (Workbook.Worksheets.Count >= aux)
Dim hojaUsuarios = Workbook.Worksheets(Workbook.Worksheets.Item(0).ToString)
Dim indice As Integer = 2
While (indice < 2000)
'Numero entrega'
If (IsNothing(hojaUsuarios.Cells("A" & indice).Value) = False) Then
ENTREGA.Add(hojaUsuarios.Cells("A" & indice).Value)
End If
'Numero Contenedor'
If (IsNothing(hojaUsuarios.Cells("B" & indice).Value) = False) Then
CONTENEDOR.Add(hojaUsuarios.Cells("B" & indice).Value)
End If
'Paquete'
If (IsNothing(hojaUsuarios.Cells("C" & indice).Value) = False) Then
PAQUETE.Add(hojaUsuarios.Cells("C" & indice).Value)
End If
'Volumen'
If (IsNothing(hojaUsuarios.Cells("D" & indice).Value) = False) Then
VOLUMEN.Add(hojaUsuarios.Cells("D" & indice).Value)
End If
indice += 1
End While
indice += 1
Catch EX As Exception
MsgBox(EX.ToString)
Return False
End Try
Return True
End Function
Function extraer_valores_planilla(ByRef ruta As String) As Boolean
ExcelPackage.LicenseContext = LicenseContext.NonCommercial
Try
Dim stream = System.IO.File.OpenRead(ruta)
Dim package = New OfficeOpenXml.ExcelPackage(stream)
'// Libro
Dim Workbook = package.Workbook
'// Hojas
Dim hojas = Workbook.Worksheets
' While (Workbook.Worksheets.Count >= aux)
Dim hojaUsuarios = Workbook.Worksheets(Workbook.Worksheets.Item(0).ToString)
Dim indice As Integer = 2
While (indice < 5000)
'Numero entrega'
If (IsNothing(hojaUsuarios.Cells("A" & indice).Value) = False) Then
NSPS.Add(hojaUsuarios.Cells("A" & indice).Value)
End If
'Numero Contenedor'
If (IsNothing(hojaUsuarios.Cells("B" & indice).Value) = False) Then
NPLANILLA.Add(hojaUsuarios.Cells("B" & indice).Value)
End If
'Paquete'
If (IsNothing(hojaUsuarios.Cells("C" & indice).Value) = False) Then
IDCONTENEDOR.Add(hojaUsuarios.Cells("C" & indice).Value)
End If
'Volumen'
If (IsNothing(hojaUsuarios.Cells("D" & indice).Value) = False) Then
PAQUETE2.Add(hojaUsuarios.Cells("D" & indice).Value)
End If
If (IsNothing(hojaUsuarios.Cells("E" & indice).Value) = False) Then
VOLUMEN2.Add(hojaUsuarios.Cells("E" & indice).Value)
End If
indice += 1
End While
indice += 1
Catch EX As Exception
MsgBox(EX.ToString)
Return False
End Try
Return True
End Function
Public Sub LIMPIAR_VARIABLES_REMATE()
ENTREGA.Clear()
CONTENEDOR.Clear()
PAQUETE.Clear()
VOLUMEN.Clear()
End Sub
Public Sub LIMPIAR_VARIABLES_PLANILLA()
ENTREGA.Clear()
CONTENEDOR.Clear()
PAQUETE.Clear()
VOLUMEN.Clear()
End Sub
and on the main file i have this
Imports System.IO
Imports System.Text.RegularExpressions Imports OfficeOpenXml Imports OfficeOpenXml.Style
Public Class Form1 Private Sub Label1_Click(sender As Object, e As EventArgs) Handles Label1.Click
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim OFD As New OpenFileDialog
OFD.Title = "Selecciona un archivo"
OFD.Filter = "XLSX|*.xlsx"
If OFD.ShowDialog() = DialogResult.OK Then
Dim extension As String = System.IO.Path.GetExtension(OFD.FileName)
Dim nombreOriginal As String = System.IO.Path.GetFullPath(OFD.FileName)
TextBox1.Text = nombreOriginal
extraer_valores_remate(nombreOriginal)
Button4.Enabled = True
Button3.Enabled = True
Else
MsgBox("Campo Requerido", MsgBoxStyle.Exclamation, Title:="Faltan Datos")
TextBox1.Focus()
End If
End Sub
Public nombre_archivo As String = ""
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
Dim OFD As New OpenFileDialog
OFD.Title = "Selecciona un archivo"
OFD.Filter = "XLSX|*.xlsx"
If OFD.ShowDialog() = DialogResult.OK Then
Dim extension As String = System.IO.Path.GetExtension(OFD.FileName)
nombre_archivo2 = System.IO.Path.GetFileName(OFD.FileName)
Dim nombreOriginal As String = System.IO.Path.GetFullPath(OFD.FileName)
TextBox2.Text = nombreOriginal
extraer_valores_planilla(nombreOriginal)
Else
MsgBox("Campo Requerido", MsgBoxStyle.Exclamation, Title:="Faltan Datos")
TextBox2.Focus()
End If
End Sub
Public nombre_archivo2 As String = ""
'********VARIABLES EXCEL DE CARGA**********'
'Public ENTREGA As New List(Of String)
'Public IDCONTENEDOR As New List(Of String)
''Public PAQUETES As New List(Of String)
'Public VOLUMEN As New List(Of String)
'Public NSPS As New List(Of String)
'Public NPLANILLA As New List(Of String)
'Public IDCONTENERDOR2 As New List(Of String)
'' Public PAQUETES2 As New List(Of String)
'Public VOLUMEN2 As New List(Of String)
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
LIMPIAR_VARIABLES_REMATE()
TextBox1.Text = ""
MsgBox("Las variables del remate se han limpiado correctamente", MsgBoxStyle.Information, Title:="LIMPIAR")
End Sub
Private Sub Button5_Click(sender As Object, e As EventArgs) Handles Button5.Click
ExcelPackage.LicenseContext = LicenseContext.NonCommercial
Dim path As String = seleccionardirectorio("Excel|.xlsx")
If (String.IsNullOrWhiteSpace(path) = False) Then
Dim excel = New ExcelPackage(New FileInfo(path))
excel.Workbook.Worksheets.Add("Hoja1")
Dim aux As Integer = 1
Dim Workbook = excel.Workbook
Dim hojas = Workbook.Worksheets
Dim hoja1 = Workbook.Worksheets("Hoja1")
'DAMOS NOMBRE A LAS COLUMNAS
INICIALIZAR_PLANILLA(hoja1)
While (aux <= CONTENEDOR.Count)
hoja1.Cells("C" & aux + 1).Value = ENTREGA.Item(aux - 1)
aux += 1
End While
aux = 1
While (aux <= IDCONTENEDOR.Count)
hoja1.Cells("A" & aux + 1).Value = NSPS.Item(aux - 1)
aux += 1
End While
aux = 1
While (aux <= IDCONTENEDOR.Count)
hoja1.Cells("B" & aux + 1).Value = NPLANILLA.Item(aux - 1)
aux += 1
End While
aux = 1
While (aux <= IDCONTENEDOR.Count)
hoja1.Cells("D" & aux + 1).Value = IDCONTENEDOR.Item(aux - 1)
aux += 1
End While
aux = 1
While (aux <= IDCONTENEDOR.Count)
hoja1.Cells("E" & aux + 1).Value = PAQUETE2.Item(aux - 1)
aux += 1
End While
aux = 1
While (aux <= IDCONTENEDOR.Count)
hoja1.Cells("F" & aux + 1).Value = VOLUMEN2.Item(aux - 1)
'Cambiar color de la celda ocupar este codigo'
'hoja1.Cells("A" & aux + 1).Style.Fill.PatternType = ExcelFillStyle.Solid
'hoja1.Cells("A" & aux + 1).Style.Fill.BackgroundColor.SetColor(Color.Red)
aux += 1
End While
aux = 1
excel.Save()
MsgBox("Documento Creado Correctamente", MsgBoxStyle.Information, Title:="Operacion Correcta")
Process.Start(path)
End If
End Sub
Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
LIMPIAR_VARIABLES_PLANILLA()
TextBox2.Text = ""
MsgBox("Las variables de la planilla se han limpiado correctamente", MsgBoxStyle.Information, Title:="LIMPIAR")
End Sub
Private Sub TextBox2_TextChanged(sender As Object, e As EventArgs) Handles TextBox2.TextChanged
End Sub
End Class
so as you can this does not compare the two excel and it just shows me information
Any ideas on how to do this?
Thanks in advance
you need to match the rows by combining 2 loops.
For each itemfromfile1 in file1
for each itemfromfile2 in file2
' Match 2 rows with each other
if itemfromfile1.SomeField = itemfromfile2.SomeField then
' These are the linked rows between the 2 documents
end if
next
next
Simple fill in the pseudo variables with the code that your office implementation uses.
I'm suffering with this VB.Net 2017 code which is supposed to check if Proxies working or not. Sometimes it reach to an end successfully, and sometimes the program never reach and end or take lots of time to do so, although I have specified the timeout for every webrequest to be 11000... Also, the list of working proxies always has duplicates! I don't know how that happens, althoug the original (raw) list is unique!
Could you please help? This is supposed to wait till the 99 threads finished then another 99 (or the remaining threads) kick-started.
P.S. MYWEBSITE.com works for me only and it displays the IP address of the visitor, i.e. to double check if the proxy has worked fine
Imports System.Net
Imports System.IO
Imports System
Imports System.Text.RegularExpressions
Imports System.Threading
Public Class frmMain
Dim FinalWorkingProxies As New List(Of String)()
Private Sub btnBrowse_Click(sender As Object, e As EventArgs) Handles btnBrowse.Click
Control.CheckForIllegalCrossThreadCalls = False
PB.Maximum = txtRawIP.Lines.Count
PB.Value = 0
StartCheckingIP(0)
End Sub
Function StartCheckingIP(ByVal num As Integer)
For I As Integer = num To txtRawIP.Lines.Count - 1
Dim StrIPOnly As String = txtRawIP.Lines(I)
StrIPOnly = Trim(StrIPOnly.TrimStart("0"c)) 'remove any leading zeros
Try
Dim clsThreads As New System.Threading.Thread(AddressOf CheckIP)
clsThreads.Start(StrIPOnly)
Catch ex As Exception
MsgBox(I)
End Try
If (I > 0 And (I Mod 99 = 0)) Then Exit For
Next
Return True
End Function
Private Function CheckIP(ByVal Prox As String) As Boolean
'txtHTML.Text += vbCrLf & Prox
'txtHTML.Refresh()
Dim txtWebResult As String = ""
Dim OriginalFullProx As String = Trim(Prox)
Dim proxyObject As WebProxy = New WebProxy("http://" & OriginalFullProx & "/")
proxyObject.BypassProxyOnLocal = True
Prox = Prox.Substring(0, Prox.IndexOf(":"))
Dim sURL As String
sURL = "http://MYWEBSITE.com/testip.php"
Dim wrGETURL As WebRequest
wrGETURL = WebRequest.Create(sURL)
wrGETURL.Proxy = proxyObject
wrGETURL.Timeout = 6000
txtWebResult = "Dosn't work"
Try
Dim objStream As Stream
objStream = wrGETURL.GetResponse.GetResponseStream
Dim objReader As New StreamReader(objStream)
Dim sLine As String = ""
sLine = objReader.ReadLine
If Not sLine Is Nothing Then
txtWebResult = sLine
End If
txtWebResult = Regex.Replace(txtWebResult, “^\s+$[\r\n]*”, “”, RegexOptions.Multiline)
If (Trim(Prox) = Trim(txtWebResult)) Then
FinalWorkingProxies.Add(OriginalFullProx)
End If
Catch ex As Exception
txtWebResult = "Dosn't work"
End Try
If (PB.Value < PB.Maximum) Then PB.Value += 1
PB.Refresh()
If (PB.Value = PB.Maximum) Then
txtFilteredIP.Clear()
Randomize()
Dim RRR As Integer = CInt(Math.Ceiling(Rnd() * 1000)) + 1
Thread.Sleep(RRR)
If (txtFilteredIP.Text <> "") Then Return False
Dim str As String
For Each str In FinalWorkingProxies
txtFilteredIP.Text += str & vbCrLf
Next
ElseIf ((PB.Value - 1) > 0 And ((PB.Value - 1) Mod 99 = 0)) Then
StartCheckingIP(PB.Value)
End If
Return True
End Function
Private Sub txtRawIP_TextChanged(sender As Object, e As EventArgs) Handles txtRawIP.TextChanged
lblRawIPTotal.Text = "Total: " & txtRawIP.Lines.Count
End Sub
Private Sub txtFilteredIP_TextChanged(sender As Object, e As EventArgs) Handles txtFilteredIP.TextChanged
lblFilteredIPTotal.Text = "Total: " & txtFilteredIP.Lines.Count
End Sub
End Class
Here is the modified code, but it stills takes long of time to finalize long list of proxies, although I sat max concurrent connection to 2000 and timeout to 8sec. Please help. Thanks.
Public Class frmMain
Dim FinalWorkingProxies As New List(Of String)()
Private Sub btnBrowse_Click(sender As Object, e As EventArgs) Handles btnBrowse.Click
'Control.CheckForIllegalCrossThreadCalls = False
ServicePointManager.Expect100Continue = False
ServicePointManager.DefaultConnectionLimit = 2000
'ServicePointManager.Expect100Continue = True
FinalWorkingProxies.Clear()
PB.Maximum = txtRawIP.Lines.Count
PB.Value = 0
StartCheckingIP(0)
End Sub
Function StartCheckingIP(ByVal num As Integer)
For I As Integer = num To txtRawIP.Lines.Count - 1
Dim StrIPOnly As String = txtRawIP.Lines(I)
StrIPOnly = Trim(StrIPOnly.TrimStart("0"c)) 'remove any leading zeros
Try
Dim clsThreads As New System.Threading.Thread(AddressOf CheckIP)
clsThreads.Start(StrIPOnly)
Catch ex As Exception
MsgBox(I)
End Try
If (I > 0 And (I Mod 333 = 0)) Then Exit For
Next
Return True
End Function
Private Function CheckIP(ByVal Prox As String) As Boolean
'txtHTML.Text += vbCrLf & Prox
'txtHTML.Refresh()
Dim txtWebResult As String = ""
Dim OriginalFullProx As String = Trim(Prox)
Dim proxyObject As WebProxy = New WebProxy("http://" & OriginalFullProx & "/")
proxyObject.BypassProxyOnLocal = True
Prox = Prox.Substring(0, Prox.IndexOf(":"))
Dim sURL As String
sURL = "http://MYWEBSITE.com/testip.php"
Dim wrGETURL As WebRequest
wrGETURL = WebRequest.Create(sURL)
wrGETURL.Proxy = proxyObject
wrGETURL.Timeout = 8000
txtWebResult = "Dosn't work"
Try
Dim objStream As Stream
objStream = wrGETURL.GetResponse.GetResponseStream
Dim objReader As New StreamReader(objStream)
Dim sLine As String = ""
sLine = objReader.ReadLine
If Not sLine Is Nothing Then
txtWebResult = sLine
End If
txtWebResult = Regex.Replace(txtWebResult, “^\s+$[\r\n]*”, “”, RegexOptions.Multiline)
If (Trim(Prox) = Trim(txtWebResult)) Then
'Now know exact country
sURL = "http://ip-api.com/xml/" & Prox
wrGETURL = WebRequest.Create(sURL)
wrGETURL.Proxy = proxyObject
wrGETURL.Timeout = 8000
objStream = wrGETURL.GetResponse.GetResponseStream
Dim objReader2 As New StreamReader(objStream)
Dim FullCODEOFAPI As String = objReader2.ReadToEnd()
Dim XMLR As XmlReader
XMLR = XmlReader.Create(New StringReader(FullCODEOFAPI))
XMLR.ReadToFollowing("country")
XMLR.Read()
OriginalFullProx += "-" + XMLR.Value
FinalWorkingProxies.Add(OriginalFullProx)
End If
Catch ex As Exception
txtWebResult = "Dosn't work"
End Try
If (PB.Value < PB.Maximum) Then UpdatePB(1)
If (PB.Value = PB.Maximum) Then
UpdateFilteredList(1)
ElseIf ((PB.Value - 1) > 0 And ((PB.Value - 1) Mod 333 = 0)) Then
StartCheckingIP(PB.Value)
End If
Return True
End Function
Private Delegate Sub UpdatePBDelegate(ByVal PBVal As Integer)
Private Sub UpdatePB(ByVal PBVal As Integer)
If PB.InvokeRequired Then
PB.Invoke(New UpdatePBDelegate(AddressOf UpdatePB), New Object() {PBVal})
Else
PB.Value += PBVal
PB.Refresh()
End If
End Sub
Private Delegate Sub UpdateFilteredListDelegate()
Private Sub UpdateFilteredList(ByVal TMP As Integer)
If txtFilteredIP.InvokeRequired Then
txtFilteredIP.Invoke(New UpdatePBDelegate(AddressOf UpdateFilteredList), New Object() {TMP})
Else
txtFilteredIP.Clear()
Dim str As String
For Each str In FinalWorkingProxies
txtFilteredIP.Text += str & vbCrLf
Next
End If
End Sub
Private Sub txtRawIP_TextChanged(sender As Object, e As EventArgs) Handles txtRawIP.TextChanged
lblRawIPTotal.Text = "Total: " & txtRawIP.Lines.Count
End Sub
Private Sub txtFilteredIP_TextChanged(sender As Object, e As EventArgs) Handles txtFilteredIP.TextChanged
lblFilteredIPTotal.Text = "Total: " & txtFilteredIP.Lines.Count
End Sub
Private Sub btnLoadList_Click(sender As Object, e As EventArgs) Handles btnLoadList.Click
OFD.ShowDialog()
If (OFD.FileName <> "") Then
txtRawIP.Text = File.ReadAllText(OFD.FileName)
End If
End Sub
End Class
Here is my code:
Imports System.Net
Imports System.Net.Sockets
Public Class Form1
Dim socketz As New Socket(AddressFamily.InterNetwork, SocketType.Raw, ProtocolType.IP)
Dim bytedata(4096) As Byte
Dim myip As IPAddress
Dim started As Boolean = True
Dim sizediff As Size
Dim formloaded As Boolean = False
Dim FilterIPAddress As New IPAddress(0)
Dim FilterIP As Boolean
Dim mycomputerconnections() As Net.NetworkInformation.NetworkInterface
'datagridview1 Update stuff
Dim stringz As String = ""
Dim Typez As String = ""
Dim ipfrom As IPAddress
Dim ipto As IPAddress
Dim destinationport As String = ""
Dim sourceport As String = ""
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
sizediff.Height = Me.Height - DataGridView1.Height
sizediff.Width = Me.Width - DataGridView1.Width
formloaded = True
mycomputerconnections = Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces
For i = 0 To mycomputerconnections.Length - 1
Combobox1.Items.Add(mycomputerconnections(i).Name)
Next
End Sub
Private Sub OnReceive(ByVal asyncresult As IAsyncResult)
If started = True Then
'Get Length of packet (including header)
Dim readlength As UInteger = BitConverter.ToUInt16(Byteswap(bytedata, 2), 0)
sourceport = BitConverter.ToUInt16(Byteswap(bytedata, 22), 0)
destinationport = BitConverter.ToUInt16(Byteswap(bytedata, 24), 0)
'Get Protocol Type
If bytedata(9) = 6 Then
Typez = "TCP"
ElseIf bytedata(9) = 17 Then
Typez = "UDP"
Else
Typez = "???"
End If
'Get IP from and to
ipfrom = New IPAddress(BitConverter.ToUInt32(bytedata, 12))
ipto = New IPAddress(BitConverter.ToUInt32(bytedata, 16))
'If this is a packet to/from me and not from myself then...
If (ipfrom.Equals(myip) = True Or ipto.Equals(myip) = True) And ipto.Equals(ipfrom) = False Then
If FilterIP = False Or (FilterIP = True And (FilterIPAddress.Equals(ipfrom) Or FilterIPAddress.Equals(ipto))) Then
'Fix data
stringz = ""
For i = 26 To readlength - 1
If Char.IsLetterOrDigit(Chr(bytedata(i))) = True Then
stringz = stringz & Chr(bytedata(i))
Else
stringz = stringz & "."
End If
Next
'Put data to DataGridView, since it's on a different thread now, invoke it
DataGridView1.Invoke(New MethodInvoker(AddressOf datagridview1Update))
End If
End If
End If
'Restart the Receiving
socketz.BeginReceive(bytedata, 0, bytedata.Length, SocketFlags.None, New AsyncCallback(AddressOf OnReceive), Nothing)
End Sub
Private Sub datagridview1Update()
'Remove rows if there are too many
If DataGridView1.Rows.Count > 9 Then
DataGridView1.Rows.RemoveAt(0)
End If
DataGridView1.Rows.Add()
DataGridView1.Rows(DataGridView1.Rows.Count - 2).Cells(0).Value = ipfrom.ToString 'From Column, size at 125
DataGridView1.Rows(DataGridView1.Rows.Count - 2).Cells(1).Value = ipto.ToString 'To Column, size at 125
DataGridView1.Rows(DataGridView1.Rows.Count - 2).Cells(2).Value = destinationport.ToString
DataGridView1.Rows(DataGridView1.Rows.Count - 2).Cells(3).Value = sourceport.ToString
End Sub
Private Function Byteswap(ByVal bytez() As Byte, ByVal index As UInteger)
Dim result(1) As Byte
result(0) = bytez(index + 1)
result(1) = bytez(index)
Return result
End Function
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If started = True Then
Button1.Text = "Start"
started = False
Else
Button1.Text = "Stop"
started = True
End If
End Sub
Private Sub Form1_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Resize
If formloaded = True Then
DataGridView1.Size = Me.Size - sizediff
End If
End Sub
Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Combobox1.SelectedIndexChanged
For i = 0 To mycomputerconnections(Combobox1.SelectedIndex).GetIPProperties.UnicastAddresses.Count - 1
If mycomputerconnections(Combobox1.SelectedIndex).GetIPProperties.UnicastAddresses(i).Address.AddressFamily = Net.Sockets.AddressFamily.InterNetwork Then
myip = mycomputerconnections(Combobox1.SelectedIndex).GetIPProperties.UnicastAddresses(i).Address
BindSocket()
End If
Next
End Sub
Private Sub BindSocket()
Try
socketz.Bind(New IPEndPoint(myip, 0))
socketz.SetSocketOption(SocketOptionLevel.IP, SocketOptionName.HeaderIncluded, True)
Dim bytrue() As Byte = {1, 0, 0, 0}
Dim byout() As Byte = {1, 0, 0, 0}
socketz.IOControl(IOControlCode.ReceiveAll, bytrue, byout)
socketz.Blocking = False
ReDim bytedata(socketz.ReceiveBufferSize)
socketz.BeginReceive(bytedata, 0, bytedata.Length, SocketFlags.None, New AsyncCallback(AddressOf OnReceive), Nothing)
Combobox1.Enabled = False
Catch ex As Exception
Combobox1.BackColor = Color.Red
End Try
End Sub
End Class
Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
Try
If TextBox1.Text <> "" And TextBox1.Text IsNot Nothing Then
FilterIPAddress = IPAddress.Parse(TextBox1.Text)
FilterIP = True
TextBox1.BackColor = Color.LimeGreen
Else
FilterIP = False
TextBox1.BackColor = Color.White
End If
Catch ex As Exception
FilterIP = False
TextBox1.BackColor = Color.White
End Try
End Sub
I'm trying to filter my DataGridView to only show the TextBox1's value of the sourceport column.
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"
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?