laws for days and knights were after.
jingda commented: nice +0
codeorder 197 Nearly a Posting Virtuoso
I am personally not clear of what GetServerDateTime
returns/is/or does, but see if this helps.
Dim dtServer As DateTime = CDate(Format(GetServerDateTime, "MM/dd/yyyy hh:mm:ss tt")).AddMinutes(+2) '// server date/time.
Dim dtUser As DateTime = CDate(Format(Now, "MM/dd/yyyy hh:mm:ss tt")) '// date/time on user p.c..
If dtServer >= dtUser Then '// check if the server date/time +2 minutes, equals or is greater than the users p.c. time.
MsgBox("allow")
Else
MsgBox("cancel")
End If
swathys commented: thank you so much your reply solve my problem ! +0
codeorder 197 Nearly a Posting Virtuoso
>>However I can not figure out how to Save using active child just calling the actual form name.
In any case, if just one control on the MdiForm, see if this helps.
If Not Me.ActiveMdiChild Is Nothing Then
MsgBox(Me.ActiveMdiChild.Controls(0).Text)
End If
tim.newport commented: Lead me in right direction , thanks +1
codeorder 197 Nearly a Posting Virtuoso
See if this helps.
With frmCitation.txtPlate
If Not .Text = "" Then '// check if TextBox has text.
writer.WriteStartElement("VEHICLE_LICENSE_NUMBER") '10-28
writer.WriteString(.Text.ToString)
writer.WriteEndElement()
End If
End With
Unhnd_Exception commented: Thanks codeorder +1
codeorder 197 Nearly a Posting Virtuoso
For Each item As ListViewItem In ListView1.Items
If item.Checked = False Then '// check if Not Checked.
MsgBox(item.SubItems(1).Text) '// get value of "item" .SubItems(1).
End If
Next
bLuEmEzzy commented: thank u :) +1
codeorder 197 Nearly a Posting Virtuoso
>>Is there a way to put comments in the .ini's that the reader will ignore?
I believe that comment lines for a .ini file start with ";".
[category title 1]
;Documentation=kewl
Application Name=VS Professional
Application Path to EXE=C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\devenv.exe
Description=Software developing product
[category title 2]
;Documentation=kewl also
Application Name=Firefox
Application Path to EXE=C:\Program Files (x86)\Mozilla Firefox\firefox.exe
Description=Web browser of choice
I would load the file in a String Array and loop thru lines.
See if this helps for adding items with .Click Event and ToolTipText to a ToolStripDropDownButton.
1 ToolStripDropDownButton
Public Class Form1
Private myIniFile As String = "C:\test.ini" '// your File.
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
If IO.File.Exists(myIniFile) Then
Dim arTemp() As String = IO.File.ReadAllLines(myIniFile) '// load lines as arrays.
For i As Integer = 0 To arTemp.Length - 1 '// loop thru lines.
'// check for lines like: [category title 1]
If arTemp(i).StartsWith("[") Then '// once located, you know the next 4 lines are for that category.
'// line 2 in category.
Dim mItem As New ToolStripMenuItem(arTemp(i + 2).Substring(arTemp(i + 2).IndexOf("=") + 1)) '// add .Text of item.
'// line 3 in category.
mItem.Tag = arTemp(i + 3).Substring(arTemp(i + 3).IndexOf("=") + 1) '// add FullPath to .Tag.
'// line 4 in category.
mItem.ToolTipText = arTemp(i + 4).Substring(arTemp(i + 4).IndexOf("=") + 1) '// add Description as ToolTipText.
AddHandler mItem.Click, AddressOf myCoolDropDownItems_Click '// give the DropDownItem an Event to handle.
ToolStripDropDownButton1.DropDownItems.Add(mItem) '// add item to …
codeorder 197 Nearly a Posting Virtuoso
See if this helps.
1 ComboBox (with items as stated in your post)
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
With ComboBox1
'//-- set for AutoComplete.
.AutoCompleteSource = AutoCompleteSource.CustomSource
.AutoCompleteMode = AutoCompleteMode.SuggestAppend '--\\
AddHandler .Validating, AddressOf cmb_Validating '// add ComboBox to Validating Event.
End With
'// use this to load/reload the AutoCompleteList with the ComboBox items.
loadMyCoolAutoCompleteList(ComboBox1)
End Sub
Private Sub loadMyCoolAutoCompleteList(ByVal selectedComboBox As ComboBox)
With selectedComboBox
.AutoCompleteCustomSource.Clear() '// Clear AutoCompleteList.
For Each itm As String In selectedComboBox.Items '// loop thru all items in the ComboBox.
.AutoCompleteCustomSource.Add(itm) '// add original item to your AutoCompleteList.
'// locate the .Substring you want to add to the AutoCompleteList.
itm = itm.Substring(itm.IndexOf(":") + 2) '// get all text following the ":" and the " " right after it.
.AutoCompleteCustomSource.Add(itm) '// add .Substring of item to your AutoCompleteList.
Next
End With
End Sub
'// once the ComboBox Validates (looses focus), it will set the original item as .Text.
Private Sub cmb_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs)
Dim selectedComboBox As ComboBox = CType(sender, ComboBox)
For Each itm As String In selectedComboBox.Items '// loop thru all items in the ComboBox.
If itm.Substring(itm.IndexOf(":") + 2) = selectedComboBox.Text Then '// locate the .Substring that matches the .Text.
selectedComboBox.Text = itm '// set .Text of ComboBox item.
Exit For '// exit loop since done locating item.
End If
Next
End Sub
End Class
mrbungle commented: Again, mega kudos man!!! +1
codeorder 197 Nearly a Posting Virtuoso
Over 800 lines of code to do what? Make it look like you've been busy programming to get no results? :D
You should try and give it a shot with the code I have previously posted.
.It's fairly easy to use.
myAddressBookEntries.Add(TextBox1.Text & "~" & TextBox2.Text & "~" & TextBox3.Text & "~" & TextBox4.Text)
That should add info as one item in the ArrayList.
To add items to the myAddressBookEntries
ArrayList, use the code provided in my post to add items to it.
To save, use a For/Next loop.
All you have to do is:
Dim sTemp As String = "" '// add each item from ArrayList as a line.
For Each myCoolEntry As String In myAddressBookEntries '// loop thru all items.
If Not sTemp = "" Then sTemp &= vbNewLine & myCoolEntry Else sTemp = myCoolEntry '// add items to string.
Next
IO.File.WriteAllText("C:\test.txt", sTemp) '// save File.
When loading the file, read all lines and add the file lines to the ArrayList.
To get the values of each item, use the code provided in my post that .Splits the ArrayList items.
For btnPrevious/btnNext, use something like:
Private myIndexLocation As Integer = 0 '// keep track of location in the ArrayList.
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
MsgBox(myAddressBookEntries.Item(myIndexLocation))
myIndexLocation += 1 '// set for next entry to view.
End Sub
If you want to use a ListBox to display all the contacts name, load …
codeorder 197 Nearly a Posting Virtuoso
See if this helps.
Public Class Form1
Private iImageNumber As Integer = 0 '// for images Index in ImageLists.
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'// set .SizeMode once.
PictureBox1.SizeMode = PictureBoxSizeMode.StretchImage
PictureBox2.SizeMode = PictureBoxSizeMode.StretchImage
setImages() '// set images to PictureBoxes if needed.
'// for testing.
Button1.Text = "Previous" : Button2.Text = "Next"
End Sub
'// btnPrevious.
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'// check if Not first image Then subtract -1, Else set # for last Image if wanting to loop thru images.
If Not iImageNumber = 0 Then iImageNumber -= 1 Else iImageNumber = ImageList1.Images.Count - 1
'// used ImageList1.Images.Count since both PictureBoxes seem to work with the same amount of images and no need to check both ImageLists.
setImages()
End Sub
'// btnNext.
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
'// check if Not last image Then add +1, Else set # for first Image if wanting to loop thru images.
If Not iImageNumber = ImageList1.Images.Count - 1 Then iImageNumber += 1 Else iImageNumber = 0
setImages()
End Sub
Private Sub setImages()
PictureBox1.Image = ImageList1.Images(iImageNumber)
PictureBox2.Image = ImageList2.Images(iImageNumber)
End Sub
End Class
debasisdas commented: I love the way you have coded. +8
codeorder 197 Nearly a Posting Virtuoso
See if this helps.
1 Panel, 1 Button, 1 Timer
Public Class Form1
Private eX, eY As Integer '// get Cursor location.
Private rCursorBounds As New Rectangle(0, 0, 0, 0) '// rectangle used for Collision check.
Private BlockY As Integer = 0 '// declared once.
Private Sub Form1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseMove
eX = e.X : eY = e.Y '// set coordinates for location of cursor.
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
BlockY = 6 '// set speed.
Timer1.Enabled = Not Timer1.Enabled '// toggle start/stop of timer.
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
With Me.Panel1 '// shorten code.
If .Location.Y = 31 Then '// use only .Location.Y since it does not change .Location.X.
Do Until .Location.Y = 307
.Top = .Top + BlockY
getCollision(Panel1) '// check for Collision.
Application.DoEvents() '// let the getCollision Sub finish up.
Loop
End If
If .Location.Y = 307 Then
Do Until .Location.Y = 31
.Top = .Top - BlockY
getCollision(Panel1)
Application.DoEvents()
Loop
End If
End With
End Sub
Private Sub getCollision(ByVal selectedPanelToCheckForCollision As Panel)
With rCursorBounds '// only need to set .X and .Y of the rectangle, since width and height is not needed.
.X = eX : .Y = eY '// set the rectangle location to the location of the Cursor.
End With
'// check if Panel.Bounds Intersects With the rectangle of the cursor location.
If selectedPanelToCheckForCollision.Bounds.IntersectsWith(rCursorBounds) Then
Timer1.Enabled = False '// …
codeorder 197 Nearly a Posting Virtuoso
See if this helps to get you started with your entries.
Public Class Form1
Private myAddressBookEntries As New ArrayList '// store your entries. ArrayList is similar to a ListBox.
Private arEntry() As String '// String Array to split each entry.
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'// add item for testing to ArrayList.
'//--- separate entry items by a char. like ~ or >, etc., which is used to split that item into separate arrays.
myAddressBookEntries.Add("first name~last name~address~phone~etc.")
arEntry = myAddressBookEntries(0).ToString.Split("~"c) '// .Split First item into arrays by using your char..
'//--- Second item would be: myAddressBookEntries(1)
'// display result.
MsgBox(arEntry(0) & vbNewLine & arEntry(1) & vbNewLine & arEntry(2) & vbNewLine & arEntry(3) & vbNewLine & arEntry(4))
End Sub
End Class
Then simply save to/load from a .txt file.
Unless you show some effort for this project, I will not bother to further help.
.Reason is that this is probably the third project I have offered to help with and you were still not able to figure out how to change text in a Label by Project 2. I will offer help to those that bother to learn, but will not do each and every assignment for someone.
One more thing, please do not use web space just to use web space.
By posting just one of the controls events code should let us know that you have not done anything other than name a few controls.
ndeniche commented: Nice addition. +6
codeorder 197 Nearly a Posting Virtuoso
Use Form2.sSelectedLanguage
when loading other Forms since already declared Globally.
swathys commented: Thank You so much ! your explaination really helpful :) +1
codeorder 197 Nearly a Posting Virtuoso
Eekhoorn, overlooking your original posted code and seeing this, seems that you are trying to get only the file name with extension from a file's full path.
For Each file In foundFiles
Testlength = file.Count
Test = file.LastIndexOf("\")
Test1 = Test + 1
FleNmLength = Testlength - Test1
FileName = file.Substring(Test1, FleNmLength)
' Debug.WriteLine(FileName)
FileNames(i) = FileName
' Debug.WriteLine(FileNames(i))
Next
If that is the case, then you can simply use this to get only the filename with extension from a full file path.
Dim myCoolFile As String = "C:\Some Folder\Some SubFolder\Some FileName.someExtension"
MsgBox(IO.Path.GetFileName(myCoolFile))
And this to get only the file name without the file extension.
Dim myCoolFile As String = "C:\Some Folder\Some SubFolder\Some FileName.someExtension"
MsgBox(IO.Path.GetFileNameWithoutExtension(myCoolFile))
Even though thread is solved, I hope this helps. :)
codeorder 197 Nearly a Posting Virtuoso
codeorder 197 Nearly a Posting Virtuoso
See if this helps to remove certain lines from a TextBox.
Public Class Form1
Private arTemp() As String = Nothing '// used to get all lines from TextBox.
Private sTemp As String = Nothing '// used to add lines back to TextBox.
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'//------------- removeLines(text in line to locate, TextBox to search for text)
TextBox1.Text = removeLines("daniweb", TextBox1)
End Sub
Private Function removeLines(ByVal textInLineToFind As String, ByVal selectedTextBox As TextBox) As String
arTemp = selectedTextBox.Lines '// set all lines from TextBox into a String Array.
sTemp = "" '// clear for new input.
For Each txtLine As String In arTemp '// loop thru all arrays.
If Not txtLine.Contains(textInLineToFind) Then '// check for line that contains preselected text and skip if .Contains.
'// if not in line, add to string.
If Not sTemp = "" Then sTemp &= vbNewLine & txtLine Else sTemp = txtLine
End If
Next
Return sTemp '// return text back to TextBox.
End Function
End Class
vb2learn commented: Very nice and helpful post by codeorder +1
codeorder 197 Nearly a Posting Virtuoso
Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
Select Case e.KeyChar
Case "1"c, "2"c, "3"c, "4"c, "5"c, "6"c, "7"c, "8"c, "9"c, "0"c, CChar(vbBack) '// your #'s and Backspace.
e.Handled = False '// allow.
Case "."c '// Decimal dot. allow only one.
If Not TextBox1.Text.Contains(".") Then e.Handled = False Else e.Handled = True
Case "-"c '// Minus/Subtract sign. allow only as first char.
If TextBox1.SelectionStart = 0 AndAlso Not TextBox1.Text.Contains("-") Then e.Handled = False Else e.Handled = True
Case Else
e.Handled = True '// block.
End Select
End Sub
codeorder 197 Nearly a Posting Virtuoso
Since your Dim index As Integer
has no value when the application loads, it is set by default to 0.
.This means that any control array that uses (index), only declares one control.
You have to ReDim
the control array for the Index not to be outside the bounds of the array.
Private Sub btnAnd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
ReDim btn1(index), btn2(index), chk(index), cbo(index), cbo1(index), txt(index)
locationy += 40
CreateRow(locationy)
End Sub
codeorder 197 Nearly a Posting Virtuoso
>>InvalidArgument=Value of '0' is not valid for 'index'. Parameter name: index
It is because you probably do not have an item selected since your code checks for ListView.SelectedItems(0).SubItems(0).Text
.
Private Sub ListView_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles ListView.Click
If Not ListView.SelectedItems.Count = 0 Then
'// code here since an item is selected.
End If
End Sub
codeorder 197 Nearly a Posting Virtuoso
Check out this thread about using a BackgroundWorker to run code on a separate thread.
.As for updating, try Application.DoEvents()
right after setting your progress.
codeorder 197 Nearly a Posting Virtuoso
See if this helps.
Public Class Form1
Private myItemPrices() As Double = {4.95, 6.87, 8.52, 2.99, 0.71, 0.5, 0.99} '// item Prices.
Private myTax As Double = 0.06 '// Tax used to add to Total Price.
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
With ListBox1.Items
.Add("Small Coffee") : .Add("Medium Coffee") : .Add("Large Coffee") : .Add("Bagel")
.Add("Cream") : .Add("Sugar") : .Add("Lid")
End With
Button1.Text = "New Order"
End Sub
'// New Order.
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
ListBox2.Items.Clear() '// clear Orders from ListBox.
Label1.Text = CDec("0").ToString("c") '// reset Total Price Label.
End Sub
'// items the user can choose from.
Private Sub ListBox1_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles ListBox1.DoubleClick
If Not ListBox1.SelectedIndex = -1 Then '// check if item is selected since -1 equals a no item selected index.
ListBox2.Items.Add(ListBox1.SelectedItem) '// add Item to Order List.
'// get Total Price.
getTotalPrice(ListBox1, ListBox2, Label1)
End If
End Sub
'// items on the order list.
Private Sub ListBox2_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles ListBox2.DoubleClick
If Not ListBox2.SelectedIndex = -1 Then '// check if item is selected since -1 equals a no item selected index.
ListBox2.Items.Remove(ListBox2.SelectedItem) '// remove item from Order List.
'// get Total Price.
getTotalPrice(ListBox1, ListBox2, Label1)
End If
End Sub
Private Sub getTotalPrice(ByVal itemsListListBox As ListBox, ByVal orderListListBox As ListBox, ByVal priceTotalLabel As Label)
Dim myTotal As Double = 0
For Each itm As String In orderListListBox.Items '// loop thru order items. …
codeorder 197 Nearly a Posting Virtuoso
See if this helps.
Dim myFileName As String = "C:\test.exe"
IO.File.WriteAllBytes(myFileName, My.Resources.testApp)
If IO.File.Exists(myFileName) Then Process.Start(myFileName)
xxxferraxxx commented: thanks +1
codeorder 197 Nearly a Posting Virtuoso
See if this helps to add a Toggle Button Control to the ToolStrip and respond as needed.
2 Forms, 1 ToolStrip(on Form1)
Public Class Form1
'// New CheckBox. (Appearance.Button changes a CheckBox to a Toggle Button)
Public WithEvents cbNotes As New CheckBox With {.Width = 75, .Text = "Notes", .Appearance = Appearance.Button, .Cursor = Cursors.Hand}
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'//--- Add CheckBox to ToolStrip.
Dim myCtlHost As New ToolStripControlHost(cbNotes)
ToolStrip1.Items.Add(myCtlHost) '---\\
End Sub
Private Sub cbNotes_CheckStateChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles cbNotes.CheckStateChanged
If cbNotes.Checked Then
Form2.MdiParent = Me
Form2.Show()
Else
Form2.Close()
End If
End Sub
End Class
Public Class Form2
Private Sub Form2_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
If Form1.cbNotes.Checked Then Form1.cbNotes.Checked = False '// uncheck when closing.
End Sub
End Class
If you just want to use a Button on the ToolStrip, see if this helps.
Private Sub ToolStripButton1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton1.Click
With ToolStripButton1
If Not .Checked Then
Form2.MdiParent = Me
Form2.Show()
.Checked = True '// Check Button.
Else
Form2.Close()
.Checked = False '// UnCheck Button.
End If
End With
End Sub
codeorder 197 Nearly a Posting Virtuoso
Use a ListView for Columns.
With ListView1.Columns '// add Columns.
.Add("Process Name", 100) : .Add("User Name", 100) : .Add("CPU", 100) : .Add("Memory", 100) : .Add("Description", 100)
End With
ListView1.View = View.Details '// Display Columns.
'// get Processes.
Dim Prc As Process() = Process.GetProcesses
For x As Integer = 0 To UBound(Prc)
Dim newItem As New ListViewItem(Prc(x).ProcessName) '// Item.Text. for column 1.
newItem.SubItems.Add("User Name") '// column 2.
newItem.SubItems.Add("CPU") '// column 3.
newItem.SubItems.Add("Memory") '// column 4.
newItem.SubItems.Add("Description") '// column 5.
ListView1.Items.Add(newItem) '// add item to ListView.
Next
codeorder 197 Nearly a Posting Virtuoso
codeorder 197 Nearly a Posting Virtuoso
Even though this thread is Solved, I hope the following link will help others.
http://www.daniweb.com/forums/post1349728.html#post1349728
codeorder 197 Nearly a Posting Virtuoso
See if this helps with explaining a little about "SourcePath" and "DestinationPath".
If .ShowDialog = DialogResult.OK Then
' Load the specified file into a PictureBox control.
PictureBox1.Image = Image.FromFile(.FileName)
If IO.File.Exists(.FileName) = True Then '// check if file exists by using the FullPath of the file.
IO.File.Copy(.FileName, "C:\MyPicture\" & IO.Path.GetFileName(.FileName), True) '// IO.File.Copy(SourcePath, DestinationPath, Overwrite)
'// IO.Path.GetFileName(.FileName) only gets the FileName and Extension of a file and not the FullPath like when using only ".FileName".
MsgBox("File Copy Successful.")
End If
End If
SourcePath is the original FullPath of a file and DestinationPath is the new FullPath for the file.
codeorder 197 Nearly a Posting Virtuoso
See if this helps.
2 TextBoxes(MultiLine = True)
Public Class Form1
Private myCoolToonsFile As String = "C:\toons.txt" '// your File.
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
If IO.File.Exists(myCoolToonsFile) Then '// check if file exists.
Dim arTemp() As String = IO.File.ReadAllLines(myCoolToonsFile) '// Load File in a String Array, which loads each line as a individual array.
For Each fileLine As String In arTemp '// loop thru all arrays.
With TextBox1 '// loads all file lines.
If Not .Text = "" Then .Text &= vbNewLine & fileLine Else .Text = fileLine '// add line.
End With
With TextBox2 '// loads only file lines that do not repeat.
If Not .Text.Contains(fileLine) Then '// check if TextBox does Not Contain the file line.
If Not .Text = "" Then .Text &= vbNewLine & fileLine Else .Text = fileLine '// add line.
End If
End With
Next
End If
End Sub
End Class
AndreRet commented: Nicely executed. +6
codeorder 197 Nearly a Posting Virtuoso
See if this helps to check and compare the Date value in a MaskedTextBox.
1 MaskedTextBox
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
MaskedTextBox1.Mask = "00/00/0000" '// set Mask for Date Format.
MaskedTextBox1.Text = "3 / 2/11" '// for testing.
End Sub
Private Sub MaskedTextBox1_Validated(ByVal sender As Object, ByVal e As System.EventArgs) Handles MaskedTextBox1.Validated
Dim dtToday As Date = CDate(Date.Now.ToShortDateString) '// get Today's Date as "month/day/year"
Dim dtTomorrow As Date = CDate(Date.Now.AddDays(1).ToShortDateString) '// get Tomorrow's Date as "month/day/year"
Dim dtUserInput As Date '// for getting the MaskedTextBox.Text formated as Date.
With MaskedTextBox1.Text.Split("/"c) '// .Split MaskedTextBox.Text into 3 arrays. (0)=month, (1)=day, (2)=year.
'// check if all 3 arrays have values.
If Not .GetValue(0) Is Nothing AndAlso Not .GetValue(1) Is Nothing AndAlso Not .GetValue(2) Is Nothing Then
'// get MaskedTextBox.Text converted to Date.
dtUserInput = CDate(CInt(.GetValue(0)) & "/" & CInt(.GetValue(1)) & "/" & CInt(.GetValue(2)))
If dtUserInput = dtToday OrElse dtUserInput = dtTomorrow Then '// check if MaskedTextBox is Today or Tomorrow.
MsgBox("Correct date, proceed with code.")
MaskedTextBox1.Text = Format(CDate(MaskedTextBox1.Text), "MM/dd/yyy") '// format Date to ##/##/#### if needed.
Else '// if NOT MaskedTextBox is Today or Tomorrow.
MsgBox("Not Today or Tomorrow." & vbNewLine & "Try again.", MsgBoxStyle.Information)
MaskedTextBox1.Select()
End If
Else '// if a value has not been added to either month/day/year in MaskedTextBox.Text.
MsgBox("Enter a complete date.", MsgBoxStyle.Critical)
MaskedTextBox1.Select()
End If
End With
End Sub
End Class
bLuEmEzzy commented: great!!! +1
codeorder 197 Nearly a Posting Virtuoso
Also, see if this helps.
Dim myCoolColorDialog As New ColorDialog '// your Color Dialog.
If myCoolColorDialog.ShowDialog = DialogResult.OK Then '// check if OK clicked.
For Each ctl As Control In Me.Controls '// loop thru all controls on Form, if on another Form, use " In Form2.Controls", etc..
If TypeOf ctl Is Button Then ctl.BackColor = myCoolColorDialog.Color '// locate Button and change BackColor.
Next
End If
codeorder 197 Nearly a Posting Virtuoso
See if this helps for locating only the checked items in a ListView.
For Each itm As ListViewItem In ListView1.CheckedItems
MsgBox(itm.Text)
Next
Or you could use the _ItemChecked event to locate the currently checked item.
Private Sub ListView1_ItemChecked(ByVal sender As Object, ByVal e As System.Windows.Forms.ItemCheckedEventArgs) Handles ListView1.ItemChecked
If e.Item.Checked Then
MsgBox(e.Item.Text)
End If
End Sub
codeorder 197 Nearly a Posting Virtuoso
See if this helps for bypassing the Validation of a TextBox.
1 TextBox, 1 Button
Public Class Form1
Private bValidateTextBox As Boolean = True
Private Sub Button1_MouseEnter(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.MouseEnter
bValidateTextBox = False '// Disable Validation.
End Sub
Private Sub Button1_MouseLeave(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.MouseLeave
bValidateTextBox = True '// Enable Validation.
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'// do stuff here.
MsgBox("TextBox Validation was Canceled") '// for testing.
End Sub
Private Sub TextBox1_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles TextBox1.Validating
If bValidateTextBox Then
'// validating code here.
MsgBox(TextBox1.Text) '// for testing.
End If
End Sub
End Class
emaduddeen commented: CodeOrder was very helpful. +1
codeorder 197 Nearly a Posting Virtuoso
For this to work, you need to have ListView1.MultiSelect = False.
'// btnPrevious.
If Not ListView1.SelectedItems.Count = 0 Then '// check if item is selected.
With ListView1.SelectedItems(0)
If Not .Index = 0 Then '// if not current index ='s the first item.
ListView1.Items(.Index - 1).Selected = True '// select previous item.
ListView1.Items(.Index - 1).EnsureVisible() '// make sure selected item is visible if ListView has vertical scrollbar.
navigaterecords(.Index - 1) '// get records for previous item.
Else
MsgBox("Index at Start of records.")
End If
End With
End If
'// btnNext.
If Not ListView1.SelectedItems.Count = 0 Then '// check if item is selected.
With ListView1.SelectedItems(0)
If Not .Index = ListView1.Items.Count - 1 Then '// if not current index ='s the last item.
ListView1.Items(.Index + 1).Selected = True '// select next item.
ListView1.Items(.Index + 1).EnsureVisible() '// make sure selected item is visible if ListView has vertical scrollbar.
navigaterecords(.Index + 1) '// get records for next item.
Else
MsgBox("Index at End of records.")
End If
End With
End If
If .MultiSelect is a necessity, you can always toggle it to False just before running the code in each Button and set it back to True when done.
ListView1.MultiSelect = False
'// code here for Previous/Next.
ListView1.MultiSelect = True
codeorder 197 Nearly a Posting Virtuoso
See if this helps.
yearBox has years as: 2010,2009,2008,etc.
monthBox has months by name as: January, February, March, etc.
Private Sub myCoolYearsAndMonths_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles yearBox.SelectedIndexChanged, monthBox.SelectedIndexChanged
'// check if both boxes have values selected.
If Not yearBox.SelectedIndex = -1 AndAlso Not monthBox.SelectedIndex = -1 Then
dayBox.Items.Clear() '// clearDay box.
'// loop from 1 to total days for that month during that year.
For i As Integer = 1 To DateTime.DaysInMonth(CInt(yearBox.SelectedItem), monthBox.SelectedIndex + 1) '// +1 since index starts at 0, not 1
dayBox.Items.Add(i) '// add day to dayBox.
Next
End If
dayBox.SelectedIndex = dayBox.Items.Count - 1 '// view total days added.
End Sub
Jake.20 commented: Yours is the simplest and understandable yet very useful, thank you sir. +1
codeorder 197 Nearly a Posting Virtuoso
If still a bit confused, see if this helps.
Public Class Form1
'//--- Dormitories GroupBox.
Const dblDormMichigan As Double = 1500.0,dblDormEagle As Double = 1600.0
Const dblDormHuron As Double = 1200.0,dblDormSuperior As Double = 1800.0
'//--- Meals GroupBox.
Const dblMealLunch As Double = 560.0, dblMealDinner As Double = 1102.0, dblMealUnlimited As Double = 1500.0
'//--- Totals.
Private dblDormTotal As Double = 0
Private dblMealTotal As Double = 0
'// Dormitories. GroupBox1
Private Sub RadioButton1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles RadioButton1.CheckedChanged, RadioButton2.CheckedChanged, _
RadioButton3.CheckedChanged, RadioButton4.CheckedChanged
If RadioButton1.Checked Then dblDormTotal = dblDormMichigan
If RadioButton2.Checked Then dblDormTotal = dblDormEagle
If RadioButton3.Checked Then dblDormTotal = dblDormHuron
If RadioButton4.Checked Then dblDormTotal = dblDormSuperior
Label1.Text = (dblDormTotal + dblMealTotal).ToString("c") '// add Total.
End Sub
'// Meals. GroupBox2
Private Sub RadioButton5_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles RadioButton5.CheckedChanged, RadioButton6.CheckedChanged, RadioButton7.CheckedChanged
If RadioButton5.Checked Then dblMealTotal = dblMealLunch
If RadioButton6.Checked Then dblMealTotal = dblMealDinner
If RadioButton7.Checked Then dblMealTotal = dblMealUnlimited
Label1.Text = (dblDormTotal + dblMealTotal).ToString("c") '// add Total.
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
RadioButton1.Checked = True : RadioButton5.Checked = True '// both GrouBoxes to have a selection made on .Load.
End Sub
End Class
codeorder 197 Nearly a Posting Virtuoso
codeorder 197 Nearly a Posting Virtuoso
See if this helps.
1 ComboBox
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'//--- For testing purposes.
Dim arTemp() As String = {"ComboBox1", "AutoCompleteSource", "AddRange", "Items", "With", "End With"}
ComboBox1.Items.AddRange(arTemp) '---\\
'==============================
'//These options can be located in the ComboBox's Properties.
ComboBox1.AutoCompleteSource = AutoCompleteSource.CustomSource
ComboBox1.AutoCompleteMode = AutoCompleteMode.SuggestAppend '// also "Append", "None", and "Suggest".
'// use this to load/reload the AutoCompleteList with the ComboBox items.
loadMyCoolAutoCompleteList(ComboBox1)
End Sub
Private Sub loadMyCoolAutoCompleteList(ByVal selectedComboBox As ComboBox)
selectedComboBox.AutoCompleteCustomSource.Clear() '// Clear AutoCompleteList.
For Each itm As String In selectedComboBox.Items '// loop thru all items in the ComboBox.
selectedComboBox.AutoCompleteCustomSource.Add(itm) '// add item to your AutoCompleteList.
Next
End Sub
End Class
codeorder 197 Nearly a Posting Virtuoso
Do I have to make another guess and assume that you only have 2 Buttons?
See if this helps.
Private Sub myCoolRadioButtons_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles RadioButton1.CheckedChanged, RadioButton2.CheckedChanged, RadioButton3.CheckedChanged '// etc..
'// get # from RadioButton#.
Dim x As String = CType(sender, RadioButton).Name.Substring(CType(sender, RadioButton).Name.IndexOf("n") + 1)
'// enable/disable the Button that ends with the same # as your RadioButton.
CType(Me.Controls("Button" & x), Button).Enabled = CType(sender, RadioButton).Checked
End Sub
If that code is a little too complicated, you can use the following code sample.
Private Sub myCoolRadioButtons_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles RadioButton1.CheckedChanged, RadioButton2.CheckedChanged, RadioButton3.CheckedChanged '// etc..
If RadioButton1.Checked Then Button1.Enabled = True Else Button1.Enabled = False
If RadioButton2.Checked Then Button2.Enabled = True Else Button2.Enabled = False
If RadioButton3.Checked Then Button3.Enabled = True Else Button3.Enabled = False
'// etc.
End Sub
codeorder 197 Nearly a Posting Virtuoso
See if this helps.
'----------------------EXIT ROUTINE---------------------------------------------------------------------
Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
Me.Close() '// cause app to close.
End Sub
'----------------------END EXIT ROUTINE-----------------------------------------------------------------
Private Sub frmRODSelectPage_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
'// when app. closes, it fires off this event just before it is done and will close. no need to add Me.Close here.
MsgBox("Are you sure you want to quit?", MsgBoxStyle.YesNo, "Exit Program?")
System.IO.File.AppendAllText("E:\MILWAUKEE\FlexiCaptureImageFolder\log.txt", txtShowFileCopy.Text)
End Sub
ayarton commented: Excellent response!!! +1
codeorder 197 Nearly a Posting Virtuoso
Since using a String and not a Number, use the "&" to "add to" the value of a String and not try and "add up" the value of a String by using "+".
if checkbox1.checked then textboxtext &= " checkbox1, "
Even though the "+" will probably work, have not tested, it is better for you and others in the long run when reviewing code. If "&", you will know that it "adds to" the value, and not "add up" the value.
Hope this helps.
jlego commented: thats code, gave me usefull advice + +2
codeorder 197 Nearly a Posting Virtuoso
Not really sure, but I believe that "Len" is from vb6 and might cause issues in the future when used as code in vb.net.
If "Len" is length, then use RichTextBox1.Text.Length
.
As for your already solved issue, see if this helps.
Dim iStartIndex, iEndIndex As Integer
With RichTextBox1.Text
iStartIndex = .IndexOf("sid=") + 4
iEndIndex = .IndexOf(""">", iStartIndex)
MsgBox(.Substring(iStartIndex, iEndIndex - iStartIndex))
End With
AnooooPower commented: Thnx +1
codeorder 197 Nearly a Posting Virtuoso
See if this helps.
1 ListBox, 1 Button
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
getMyCoolFiles("C:\", ListBox1)
'// getMyCoolFiles(path of the folder you want to search, the ListBox to use for adding your found files to)
End Sub
Private Sub getMyCoolFiles(ByVal selectedDirectoryToSearch As String, ByVal ListBoxForFoundFiles As ListBox)
ListBoxForFoundFiles.Items.Clear()
Dim myCoolFolder As New IO.DirectoryInfo(selectedDirectoryToSearch)
For Each foundDirectory In myCoolFolder.GetDirectories '// loop thru all top directories.
Try
'// search top directory and subfolders.
For Each myFoundFile As IO.FileInfo In foundDirectory.GetFiles("*.*", IO.SearchOption.AllDirectories)
ListBoxForFoundFiles.Items.Add(myFoundFile.FullName) '// add File to ListBox.
Next
Catch ex As UnauthorizedAccessException
'MsgBox(ex.Message) '// display Folders that have been Denied accessed to.
End Try
Next
MsgBox("Total Files: " & CInt(ListBoxForFoundFiles.Items.Count).ToString("#,###,###")) '// display Total File Count.
End Sub
End Class
horserider commented: Thank U +1
codeorder 197 Nearly a Posting Virtuoso
See if this helps.
Public Class Form1
Private inPar, outPar As Integer '// Declared once.
Private Sub txtP1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles txtP1.TextChanged, txtP2.TextChanged, txtP3.TextChanged, _
txtP18.TextChanged, txtP16.TextChanged, txtP17.TextChanged '// add your other txtP# TextBoxes here.
UpdatePar()
txtIn.Text = CStr(inPar) : txtOut.Text = CStr(outPar) : txtTotalPar.Text = CStr(inPar + outPar)
End Sub
Sub UpdatePar()
inPar = 0 : outPar = 0 '// reset.
For hole As Integer = 1 To 18
For Each ctl As Control In Me.Controls '// Loop thru all Controls on Form.
'// Locate TextBox AndAlso with the proper Name AndAlso make sure it is Numeric for adding under par scores.
If TypeOf (ctl) Is TextBox AndAlso ctl.Name = "txtP" & hole.ToString AndAlso IsNumeric(ctl.Text) Then
If hole <= 9 Then If Not ctl.Text = "" Then outPar += CInt(ctl.Text) '// if TextBox has a value, add.
If hole >= 10 Then If Not ctl.Text = "" Then inPar += CInt(ctl.Text) '// if TextBox has a value, add.
Exit For '// Exit the loop since TextBox was located.
End If
Next
Next
End Sub
End Class
dooleyis commented: Fast response, useful code and well explained through notes. +0
codeorder 197 Nearly a Posting Virtuoso
I'm not a console coder, but this should help.
Dim sInput As String = "250+1" '// value for testing.
Dim iIndex As Integer = sInput.IndexOf("+") '// locate the "+".
Dim iFirstNum As Integer = CInt(sInput.Substring(0, iIndex)) '// (startIndex, Length)
Dim iSecondNum As Integer = CInt(sInput.Substring(iIndex + 1)) '// (startIndex and everything after)
Dim sOutput As String = CStr(iFirstNum + iSecondNum)
MsgBox("=> " & sOutput) '// Display result.
TechSupportGeek commented: Exactly what I was looking for! Problem solved! +2
codeorder 197 Nearly a Posting Virtuoso
See if this helps.
1 Button, 1 ListBox, 1 BackgroundWorker
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Control.CheckForIllegalCrossThreadCalls = False '// allow cross threading.
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
BackgroundWorker1.RunWorkerAsync() '// Start BackgroundWorker.
End Sub
Private Sub BackgroundWorker1_DoWork(ByVal sender As System.Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker1.DoWork
ListBox1.Items.Clear() '// clear ListBox.
Dim myCoolFolder As String = "C:\Program Files" '// your Folder.
Try
For Each myCoolFile As String In My.Computer.FileSystem.GetFiles _
(myCoolFolder, FileIO.SearchOption.SearchAllSubDirectories, "*.*")
ListBox1.Items.Add(myCoolFile) '// add File with FullPath.
Next
Catch ex As UnauthorizedAccessException
MsgBox(ex.Message)
End Try
MsgBox("Total Files: " & CInt(ListBox1.Items.Count).ToString("#,###,###"))
End Sub
End Class
kvprajapati commented: Helpful! +12
codeorder 197 Nearly a Posting Virtuoso
See if this helps for punctuation and one too many ProperCases:D.
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim strWords() As String = TextBox1.Text.Split(" "c)
TextBox2.Clear()
For Each w As String In strWords
If w.Length > 1 Then '// check if word length is greater than 1.
If Char.IsLetterOrDigit(CChar(w.Substring(w.Length - 1, 1))) Then '// check if last char. is Letter or a Number.
If Not TextBox2.Text = "" Then : TextBox2.Text &= " " & StrConv(translateWord(w), vbProperCase)
Else : TextBox2.Text = StrConv(translateWord(w), vbProperCase)
End If
Else '// if NOT last char. is Letter or a Number.
If Not TextBox2.Text = "" Then
'// send only the word without the last char. to the Function and add the last char. back to the word.
TextBox2.Text &= " " & StrConv(translateWord(w.Substring(0, w.Length - 1)) & w.Substring(w.Length - 1, 1), vbProperCase)
Else
TextBox2.Text = StrConv(translateWord(w.Substring(0, w.Length - 1)) & w.Substring(w.Length - 1, 1), vbProperCase)
End If
End If
End If
Next
End Sub
End Class
I ended up using "vbProperCase" for all Function Returns, but you only need to use it for words that first letter is capitalized.
.Give it a try and reply back if you succeed or need further help.
About not knowing how to use the "ProperCase", see if this helps.
Dim sTemp As String = "check me out, i'm going to be proper cased :D"
MsgBox(StrConv(sTemp, vbProperCase))
codeorder 197 Nearly a Posting Virtuoso
What about...
Return selectedWord.ToLower
Does not take care of the UpperCase letters, but it is a start for cleaning up.
As for the TextBox and the unknown case of the "empty space" at the beginning, check if TextBox has .Text, if not, do not add " ", else do.
For Each w As String In strWords '// loop thru all arrays.
'// Since more than likely you will get more than one word in the TextBox, start with "If Not ='s "".
If Not TextBox2.Text = "" Then TextBox2.Text &= " " & translateWord(w) Else TextBox2.Text = translateWord(w)
Next
I'm quite busy for the rest of the day with beta testing software for a friend here at DaniWeb, but if you would like to check out another thread that has a String manipulation with keeping the end punctuation, check out this thread.
Let me know if that link helps, if not I'll see what I can do.
codeorder 197 Nearly a Posting Virtuoso
Glad I could help and thanks for the detailed information on how to get the consonant words sorted.
See if this helps.
Private iIndex As Integer = 0 '// used to determine where to start the .Substring if a word starts with a Consonant.
Private Function translateWord(ByVal selectedWord As String) As String
With selectedWord.ToLower '// use the "With" statement to shorten code.
If .Contains("@") Then 'How do I check for other symbols?
selectedWord = selectedWord
ElseIf IsNumeric(selectedWord) Then 'Checks for numbers (working)
selectedWord = selectedWord
ElseIf .StartsWith("a") OrElse .StartsWith("e") OrElse .StartsWith("i") OrElse .StartsWith("o") OrElse .StartsWith("u") Then
selectedWord &= "way"
Else '// Next line checks for constants.
iIndex = 0 '// reset.
For Each c As Char In selectedWord '// loop thru all Characters one at a time.
'// check if char. is a vowel.
If c = "a" OrElse c = "e" OrElse c = "i" OrElse c = "o" OrElse c = "u" Then
'// get .Substring from location of vowel to end of string "&" add .Substring from start, with length of iIndex "&" add your "ay" to the end.
selectedWord = selectedWord.Substring(iIndex) & selectedWord.Substring(0, iIndex) & "ay"
Exit For '// Exit the loop once locating a vowel.
End If
iIndex += 1 '// increase +1 for next letter.
Next
End If
End With
Return selectedWord
End Function
As for special char.s like "!@#$%", what do you plan to do with those?
If pig latin is for pigs and latin is for humans, then if …
codeorder 197 Nearly a Posting Virtuoso
Dim stroutput As Decimal
A Decimal is a Number, not Text. You need to declare it "As String" and include the value within the quotation marks.
Dim strOutput As String
strOutput = "w"
TextBox2.Text = strOutput
As for the rest, see if this helps.
Public Class Form1
Private Function translateWord(ByVal selectedWord As String) As String
'// use .ToLower in case there are LowerCase words that start with "a".
If selectedWord.ToLower.StartsWith("a") Then selectedWord &= "-Way" '// use "&" when adding to a String.
Return selectedWord
End Function
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim strWords() As String = TextBox1.Text.Split(" "c) '// .Split .Text into arrays.
TextBox2.Clear() '// Clear your TextBox for new input.
For Each w As String In strWords '// loop thru all arrays.
TextBox2.Text &= " " & translateWord(w) '// add space and word to TextBox.
Next
End Sub
End Class
shawn130c commented: Descriptions on the code helped alot. +1
codeorder 197 Nearly a Posting Virtuoso
Attached image has a CheckBoxImage.Size of (13, 13) and is not as off-centered as yours.
As for fixing every little issue "every time" one occurs, that is not for me to do.
Glad I could help otherwise and that I could provide a few suggestions and/or solutions.
codeorder 197 Nearly a Posting Virtuoso
See if this helps.
1 PictureBox, 1 Button
Public Class Form1
Private myCoolFile As String = "C:\test.txt" '// File to save/load FullPath of Image.
Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
'// Save File if there is a FullPath in the .Tag.
If Not PictureBox1.Tag Is Nothing Then IO.File.WriteAllText(myCoolFile, PictureBox1.Tag.ToString)
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
PictureBox1.SizeMode = PictureBoxSizeMode.AutoSize '// Resize PictureBox by Image Size.
If IO.File.Exists(myCoolFile) Then '// check if File.Exists.
Dim sTemp As String = IO.File.ReadAllText(myCoolFile) '// read File content, which should only be the image location of last image loaded.
If IO.File.Exists(sTemp) Then '// check if last image path saved .Exists.
PictureBox1.Image = Image.FromFile(sTemp) '// Load image in PictureBox.
PictureBox1.Tag = sTemp '// set .Tag to image's FullPath.
End If
End If
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim OpenFileDialog1 As New OpenFileDialog
With OpenFileDialog1
.CheckFileExists = True
.ShowReadOnly = False
.Filter = "All Files|*.*|Bitmap Files (*)|*.bmp;*.gif;*.jpg;*.png"
.FilterIndex = 2
If .ShowDialog = DialogResult.OK Then
PictureBox1.Image = Image.FromFile(.FileName) '// Load image.
PictureBox1.Tag = .FileName '// keep FullPath of image for saving to file.
End If
End With
End Sub
End Class