Replace line 4 from your posted code with this.
Dim sr As System.IO.StreamReader = New System.IO.StreamReader(response.GetResponseStream, System.Text.Encoding.Default)
Replace line 4 from your posted code with this.
Dim sr As System.IO.StreamReader = New System.IO.StreamReader(response.GetResponseStream, System.Text.Encoding.Default)
Why not create a project that will go through the entire database and correct code?
CrLf is nothing but a line break, like vbNewLine.
See if this helps to catch the CrLf.
Dim sTemp As String = "some" & vbNewLine & vbNewLine & "text"
If sTemp.Contains(CChar(vbCrLf)) Then
MsgBox(sTemp) '// Display before.
sTemp = sTemp.Replace(vbCrLf & vbCrLf, " ") '// correct if needed.
MsgBox(sTemp) '// Display after.
End If
See if this helps.
Public Class Form1
Private myCoolConfigFile As String = "C:\test.txt" '// your File to edit.
Private arTemp() As String = Nothing '// String Array to load/modify/save File lines.
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
If IO.File.Exists(myCoolConfigFile) Then
arTemp = IO.File.ReadAllLines(myCoolConfigFile) '// Load each File line as a array.
End If
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'// editFileContent(line you want to locate, content used to modify the next line)
editFileContent("[pos]", TextBox1.Text)
End Sub
Private Sub editFileContent(ByVal lineContentToLocate As String, ByVal coolContentUsedToModifyNextLine As String)
If Not arTemp.Length = 0 Then '// check if File lines are loaded.
For i As Integer = 0 To arTemp.Length - 1 '// loop thru all lines.
If arTemp(i) = lineContentToLocate Then '// check if line equals the line you need to find.
arTemp(i + 1) = coolContentUsedToModifyNextLine '// change the next line in your array.
Exit For '// exit the loop since done editing.
End If
Next
IO.File.WriteAllLines(myCoolConfigFile, arTemp) '// Save modified File.
MsgBox("File edited and saved.")
End If
End Sub
End Class
If you need to edit another line, use: editFileContent("[lastsave]", TextBox1.Text)
. TextBox1.Text is the content to write to the file.
See if this helps.
1 Button, 1 PictureBox
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
With PictureBox1
.Left += 5
.Top += 5
End With
End Sub
To change direction of movement, use .Left -= 5
, etc..
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
See if this helps to loop through the 2D Array.
Dim iMathsAverage As Integer = 0, iEnglishAverage As Integer = 0, iScienceAverage As Integer = 0
For i As Integer = 0 To StudentArray.GetLength(0) - 1 '// loop thru all Arrays.
'// add values.
iMathsAverage += CInt(StudentArray(i, 1))
iEnglishAverage += CInt(StudentArray(i, 2))
iScienceAverage += CInt(StudentArray(i, 3))
Next
'// Result.
MsgBox("Math: " & iMathsAverage & vbNewLine & "English: " & iEnglishAverage & vbNewLine & "Science: " & iScienceAverage)
There should be no issues if having the CheckBoxes in one Panel and TextBoxes in another. Your code locates the Panel and looks for a certain control within it. txtTest.Text = CType(pnlChk.Controls(Chk.Tag.ToString), TextBox).Text
You could add all of your controls to the Form, not Panels, and loop through all of them to locate only your "txt#" TextBoxes.
For Each ctl As Control In Me.Controls
If TypeOf ctl Is TextBox AndAlso IsNumeric(ctl.Name.Substring(ctl.Name.LastIndexOf("t") + 1)) Then
ctl.BackColor = Color.LightSteelBlue
End If
Next
That will locate all TextBoxes that have a # at the end of the .Name and the letter prior to the number is "t".
You could however have the TextBoxes.Names end with "_x" for example, then only check If TypeOf ctl Is TextBox AndAlso ctl.Name.EndsWith("_x") Then
.
I just created a new project with your provided code, added "txt1" to chk1.Tag and a few other CheckBoxes, and even left out some .Tags empty. It did not crash here, ran as it should.
Only time i got it to error with: Object reference not set to an instance of an object.
is when I changed the .Tag for chk4 from "txt4" to "test4". Seems that one of your .Tags, if not all, do not have the proper Name(s) of the TextBox(es).
You could add a MsgBox in the For/Next loop to locate which CheckBox cause this issue.
If Not Chk.Tag Is Nothing Then MsgBox(Chk.Tag)
See if this helps.
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
UsernameKey("Visa")
End Sub
Private Sub UsernameKey(ByVal str As String)
If str = "Visa" OrElse str = "Master" OrElse str = "Meps" Then
MsgBox(str)
End If
End Sub
Not sure why you were using a Function since it did not have to return anything, but most of all, you were checking the Function for a value instead of checking "str" for the value.
Could be that the CheckBox.Tag is empty.
If Not Chk.Tag Is Nothing Then txtTest.Text = CType(pnlChk.Controls(Chk.Tag.ToString), TextBox).Text
Or you could use this and skip using the .Tag of a CheckBox entirely.
'// use "txt" and the # at the end of each CheckBox's Name to locate control.
txtTest.Text = CType(pnlChk.Controls("txt" & Chk.Name.Substring(Chk.Name.IndexOf("k") + 1)), TextBox).Text
If only needing the last TextBox's .Text, why not only set it once?
Dim DisCheckBox As CheckBox() = {chk1, chk2, chk3}
Dim cb As New CheckBox '// sets the checked CheckBox.
For Each Chk In DisCheckBox
If Chk.CheckState = CheckState.Checked Then cb = Chk '// locate the CheckBox if checked.
Next
If Not cb.Name = "" Then '// check if cb has a .Name. gets added if checked.
'// use "txt" and the # at the end of each CheckBox's Name to locate control.
txtTest.Text = CType(pnlChk.Controls("txt" & cb.Name.Substring(cb.Name.IndexOf("k") + 1)), TextBox).Text
End If
Can you provide a link to such a site? Should help with narrowing down a possible solution.
See if this helps.
If Not RichTextBox1.Text = "" Then '// if Not empty, add a New line and content.
RichTextBox1.Text &= vbNewLine & TextBox1.Text & " - " & TextBox2.Text
Else '// if empty, just add content.
RichTextBox1.Text = TextBox1.Text & " - " & TextBox2.Text
End If
'// Clear TextBoxes.
TextBox1.Clear() : TextBox2.Clear()
More than likely using a For/Next loop inside another.
If you still have questions regarding this new issue, start a new thread.
If you need to get the byte count for a String, see if this helps.
Dim sTemp As String = "GetByteCount"
MsgBox(System.Text.Encoding.UTF8.GetByteCount(sTemp))
Note:
There are other types of Encoding other than UTF8.
>What the h.ll I can do?
Test out different theories and see which results better your application.
You have all the needed resources in this thread to do so, you just have to find the correct code equation to do it with. That is not for me to do. I just try and supply suggestions and/or possible solutions, not create entire applications.
Good luck.
And btw, not a nice scene at all.
>...I just thought that this would make a nice scene...
Even though this thread is Solved, I hope the following link will help others.
http://www.daniweb.com/forums/post1349728.html#post1349728
...I only started today so simple techniques...
I think it was more difficult to try and come up with a easy to understand solution than to put the code together.:D
1 PictureBox, 3 Buttons(Button2 is not used, but looks good:D)
Public Class Form1
Private myCoolImagesFullPaths As New ArrayList '// Store full path of images in, just like using a ListBox.
Private mySelectedCoolImageIndex As Integer = 0 '// determines where the index is in your ArrayList.
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Button1.Text = "Previous" : Button2.Text = "Start" : Button3.Text = "Next"
'// Add Full Path of images to your ArrayList.
myCoolImagesFullPaths.Add("C:\test1.png")
myCoolImagesFullPaths.Add("C:\test2.png")
myCoolImagesFullPaths.Add("C:\test3.png")
myCoolImagesFullPaths.Add("C:\test4.png")
myCoolImagesFullPaths.Add("C:\test5.png")
'// Load first image in PictureBox.
PictureBox1.Image = Image.FromFile(myCoolImagesFullPaths(mySelectedCoolImageIndex).ToString)
'//--- myCoolImagesFullPaths(0)= image 1, myCoolImagesFullPaths(1) = image 2, myCoolImagesFullPaths(2) = image 3, etc.
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If Not mySelectedCoolImageIndex = 0 Then '// check if Not at 0.
mySelectedCoolImageIndex -= 1 '// subtract -1.
'// add new image from ArrayList.
PictureBox1.Image = Image.FromFile(myCoolImagesFullPaths(mySelectedCoolImageIndex).ToString) '// load image.
Else '// if at 0, notify user.
MsgBox("First Image.", MsgBoxStyle.Information)
End If
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
'// check if Not the index equals the total images.Count -1. -1 since Index based and starts at 0 not 1.
If Not mySelectedCoolImageIndex = myCoolImagesFullPaths.Count - 1 Then
mySelectedCoolImageIndex += 1 '// add + 1 to your Index number.
PictureBox1.Image = Image.FromFile(myCoolImagesFullPaths(mySelectedCoolImageIndex).ToString) …
The For/Next loop did not crash when I tested, but has crashed on others.
To not have it crash, since this is due the the items.Count in ListBox1, use this update for the For/Next loop.
For i As Integer = 0 To lstIndexes.Count - 1 Step 4 '// Step 4 skips to every 5 item.
arlGroup1.Add(ListBox1.Items(lstIndexes(i)))
'// check if i +1 does not equal or is greater than the items.Count in your List of Integer, Else Exit the loop.
If Not lstIndexes.Count <= i + 1 Then arlGroup2.Add(ListBox1.Items(lstIndexes(i + 1))) Else Exit For
If Not lstIndexes.Count <= i + 2 Then arlGroup3.Add(ListBox1.Items(lstIndexes(i + 2))) Else Exit For
If Not lstIndexes.Count <= i + 3 Then arlGroup4.Add(ListBox1.Items(lstIndexes(i + 3))) Else Exit For
Next
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.
See if this helps about saving and loading a color to/from a file.
Public Class Form1
Private myFile As String = "C:\test" '// File used to Save/Load Color.
Private mySelectedCoolColor As New Color '// stores loaded color from File or ColorDialog.
Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
IO.File.WriteAllText(myFile, mySelectedCoolColor.ToArgb.ToString) '// save Color to file as ARGB Color.
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
If IO.File.Exists(myFile) Then '// check if file exists.
mySelectedCoolColor = Color.FromArgb(CInt(IO.File.ReadAllText(myFile))) '// read ARGB Color and set it.
myCoolThemeColorSub(mySelectedCoolColor) '// send the Color to your Theme Sub.
End If
Me.Show()
Dim myCoolColorDialog As New ColorDialog '// your Color Dialog.
If myCoolColorDialog.ShowDialog = DialogResult.OK Then '// check if OK clicked.
mySelectedCoolColor = myCoolColorDialog.Color '// store the color to use for when saving.
myCoolThemeColorSub(mySelectedCoolColor) '// send the Color to your Theme Sub.
End If
End Sub
Private Sub myCoolThemeColorSub(ByVal myCoolColorToUse As Color)
For Each ctl As Control In Me.Controls '// loop thru all controls on Form.
If TypeOf ctl Is Button Then ctl.ForeColor = myCoolColorToUse '// locate Button and change Color.
Next
End Sub
End Class
Could you replicate a car if you did not know what the car looks like minus well know what a car is?
>But, I want that everytime it appends to the file, it replicate the file content plus the new info randomized from the array. If it could do it without reading the file,...
My answer would be that this cannot be done, although I could be wrong.
How many items is it randomizing? Just the ones from the code in your ArrayList? Then it is not the randomizing taking the time, it is the "loading the file, reading it, and saving it again".
>There isn't a way to restrict the random number range?
Dim rnd As New Random
MsgBox(rnd.Next(0, 2)) '// rnd.Next(Minimum value, Maximum value) - this will return either a 0 or a 1, not a 2.
>It is also taking too long to start the process :x
Get a faster p.c.. :D
I also noticed that for a 10 MB file, it can take a few minutes to create the file.
See if this helps.
You could run a process before starting the process to save to the file.
This process would be to save each item in your ArrayList to a file and retrieve the file size only for that item, then move on to the next item. Store the file sizes for each item either in another ArrayList of List(of Integer, and use that for references.
.Then instead of loading the file, reading it, adding a random ArrayList item to the end of the file and saving back to the file, you could just load a String in your app with random items and use the file size references to determine the "final" file size. Then save the file once and done. It might speed up your application quite a bit.
Btw, I think this process would be called: "Optimize the application on start-up for quicker results."
>Maybe is because the array randomizing?
Randomizing numbers is like giving you a choice to pick a number from 0 to 1 billion. Not time consuming at all, or is it?:D
Good luck.
>to take the names from there and randomize them into 4 groups and make it into an array also,...
I added 4 ArrayLists which store your ListBox1 items randomly. The ListBoxes 2-5 are there for '//======= FOR TESTING ==========
, unless you need them otherwise.
If you just need the items from each Group ArrayList, use MsgBox(arlGroup1(0))
to get the first item in the ArrayList for Group1, MsgBox(arlGroup1(1))
to get the second item, and so on.
Overall, you only need 1 ListBox (ListBox1) to have items in, and delete all the code just following the line of '//======= FOR TESTING ==========
.
See if this helps.
5 ListBoxes(items in ListBox1)
Public Class Form1
Private arlGroup1, arlGroup2, arlGroup3, arlGroup4 As New ArrayList '// 4 ArrayLists to store random items.
Private lstIndexes As New List(Of Integer) '// List to add random indexes to.
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
lstIndexes.Clear()
Dim rnd As New Random '// for Randomizing.
Dim iTemp As Integer = 0 '// stores a random item index.
Do While Not lstIndexes.Count = ListBox1.Items.Count '// loop until your List of Integer equals your ListBox in .Count.
iTemp = rnd.Next(0, ListBox1.Items.Count) '// get a random item index.
If Not lstIndexes.Contains(iTemp) Then lstIndexes.Add(iTemp) '// if not in List of Integer, add index of item.
Loop
'// Clear all ArrayLists.
arlGroup1.Clear() : arlGroup2.Clear() : arlGroup3.Clear() : arlGroup4.Clear()
'// loop thru all stored Indexes and add item by index from ListBox.
For i As Integer = 0 To lstIndexes.Count - 1 Step 4 '// Step 4 skips to every 5 item.
arlGroup1.Add(ListBox1.Items(lstIndexes(i)))
'// check if i +1 does not equal or is greater than the items.Count in your List of Integer, Else Exit the loop.
If Not lstIndexes.Count <= i + 1 Then arlGroup2.Add(ListBox1.Items(lstIndexes(i + 1))) Else Exit For
arlGroup3.Add(ListBox1.Items(lstIndexes(i + 2)))
arlGroup4.Add(ListBox1.Items(lstIndexes(i + 3)))
Next
'//======= FOR TESTING ==========
'// Clear ListBoxes.
ListBox2.Items.Clear() : ListBox3.Items.Clear() : ListBox4.Items.Clear() : ListBox5.Items.Clear()
'// add items from ArrayLists.
ListBox2.Items.AddRange(arlGroup1.ToArray)
ListBox3.Items.AddRange(arlGroup2.ToArray)
ListBox4.Items.AddRange(arlGroup3.ToArray)
ListBox5.Items.AddRange(arlGroup4.ToArray) '=======\\
End Sub
End Class
The 4 numbers of each rectangle are: "location.X, location.Y, Width, Height"
As for it being viable, I cannot decide that for you. You test what options are best and apply those.
I only offered a suggestion or a possible solution.
MsgBox(itm.text)
??
See if this helps.
Add a BackgroundWorker and a ProgressBar to your Form.
Imports System.IO
Public Class Main
Private FileName As String, FinalSize As Integer, arlContents As New ArrayList
Private Sub btnSearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSearch.Click
If SaveFile.ShowDialog = Windows.Forms.DialogResult.OK Then
FileName = SaveFile.FileName
lblDestinationText.Text = SaveFile.FileName
If Not File.Exists(FileName) Then File.WriteAllText(FileName, "") '// create blank file if it does not exist.
End If
End Sub
Private Sub Main_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Control.CheckForIllegalCrossThreadCalls = False '// allow cross threading for the BackgroundWorker.
comboTypes.SelectedItem = "Byte(s)"
arlContents.Add("範♓稌垫䎁᱃嵕줐㍁쉻杼煼�濴㣒�⻮왺籱ﺁ㢾䥼")
arlContents.Add("ﰓ魓�᬴윖�芚⬸쟺誸픐㹄৴留疆鹚")
arlContents.Add("ꘐ쿲쌺㪆롣泷琓蘇펁댾켍㫭片奻㠃‡軓뎄ᦚ棬뎠퇤凞꺸ᣢ⎘¬፼ા뺵禡飺譏ꜙꐊ㤮䭯ꪍ")
arlContents.Add("伣ᅹ쇏Ὣ㻿삇⪘삑튐渢ᇹ톬姙攏")
arlContents.Add("쑖퐟驿몰㦌ᩉ佯炆쏬䶅籯鏜黫伔∺㿹࣫瘺諾첼⤊ᗊ걹ᴴ狿३")
arlContents.Add("昷ퟭꫣ뻥ꮴꂍ퉅栴娕댓ʢvᄇ㺉麎褣挹�팞")
arlContents.Add("楈尳薐줛ꊓ蕣庺㞝ᾙ栳츷㹰劼ꑲ")
arlContents.Add("ᆉ斫坧ƽ䬱첷ᓨ幁窞俕꠸䜺ྨ剑旷㷈")
arlContents.Add("閘玖掼쏵脰搬䉥₃棥猂衶䌭ꡱ븗삽勵隫⽹")
arlContents.Add("斳셹茏ᢟ群共摫㵁釘꾔ޞ歅챗앑颸앚ሁ亯ꍗ")
arlContents.Add("枺鉱梉챍쉄ڸ٣躑압呀ɰ쌻ᚿ儶ᡯ纆되⼤훊替ખ뭰꜌뛆얲柾暟濶멖爱ﰱ⭜㨼껭拡练�暽羑ា聐ꪞḚ닟뒾კ趥騴䖭퉿ឺ僔缂얡")
arlContents.Add("论鈖寊₄펚⿕쵯踧ꀇ껖夡觹뭫뼤�擤露蘊ꑟ셗숪홯⣌겿ᦺ枵⨺ᄧᩨ蜋閮僨⺪膃ㅁ꽗庹⏩䊽矻䈄簤允䵟㰻ꊵ�篭遾㤨菘猐�р╔錟沂歱")
arlContents.Add("偡ࡪ꾕復눩�짌竖䰵緬�蒄鯰䮴㏁�佫뤕⎶鲦滿닡⃤薎益")
arlContents.Add("Ƥ䌤ㅪፁ솰鈆湙檣難릭偊報�឵潻댃㖖珫ꡗ詢엵꒱ヱ晼痺풷ᄒ")
arlContents.Add("ᐑ勿☑뫹ᴺ瑬浹⠯䫢ロ䏊ഝ૫怯�ಲ헑�誷ﰏ黻")
arlContents.Add("帋֚뭊灻♥櫖麘ﴣ⽮")
arlContents.Add("촳ʂ䘋ﱙꏍ큘믙贆ꀋ充Ⱐ캆ṕㄷ㕸ᢺꃿﯗ軳َ퇚䫭࢜硟毷�Ⳓﹶ䅎➬챗䨷㣩粙㽑佶㰿䴲뾿荩举┗ീ덙⁺划✞벓穛섙荣㫭nj풽쐲㥪ꒅ䐼쏦Ổ頮괫쌧唵䫁䮽㼩残ꗵ⦒娟媼뜷픽ꃛ쾮Ⴢ쪬�ἃ㥼ﵺ窸⿎ヒ퓀퇛灵待ⅹ㴺ꅬ쟹䅶鱖")
arlContents.Add("랮끰폱鋔胦쮉✭峧䜃獧뇑飡螙㿽⹋殊漷뜀灢")
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCreate.Click
'// set value for FinalSize.
If comboTypes.SelectedItem = "Bytes" Then
FinalSize = FileSize.Value
ElseIf comboTypes.SelectedItem = "Kilobytes" Then
FinalSize = FileSize.Value * 1024
ElseIf comboTypes.SelectedItem = "Megabytes" Then
FinalSize = FileSize.Value * 1024 * 1024
ElseIf comboTypes.SelectedItem = "Gigabytes" Then
FinalSize = FileSize.Value * 1024 * 1024 * 1024
End If
BackgroundWorker1.RunWorkerAsync() '// Start.
End Sub
'// RUN THE CODE ON A SEPARATE THREAD BY USING A BACKGROUNDWORKER. DOES NOT FREEZE APP. WHILE RUNNING.
Private Sub BackgroundWorker1_DoWork(ByVal sender As System.Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker1.DoWork
addContentToFile(FinalSize, FileName)
End Sub
Private Sub addContentToFile(ByVal myPresetFileSizeInBytes As Integer, ByVal myFileToAddContentTo As String)
ProgressBar1.Maximum = myPresetFileSizeInBytes
ProgressBar1.Value = 0
Dim myFileInfo As IO.FileInfo
Dim iFileSize As Integer = 0 '// keeps track of file …
Try this in a New Project.
1 TabControl and 1 ListView with items(in TabPage2)
Private Sub TabControl1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles TabControl1.SelectedIndexChanged
If TabControl1.SelectedIndex = 1 Then '// if TabPage2.
'// checkStockItemsStatus(ListView Name that you are using, Column # that you need to check(starts at 0 not 1), # of minimum allowed qty.)
checkStockItemsStatus(ListView1, 4, 5)
End If
End Sub
Private Sub checkStockItemsStatus(ByVal selectedListViewToCheck As ListView, ByVal ColumnToCheckValueFor As Integer, ByVal MinimumAllowedQuantity As Integer)
For Each itm As ListViewItem In selectedListViewToCheck.Items '// loop thru all items.
If CInt(itm.SubItems(ColumnToCheckValueFor).Text) <= MinimumAllowedQuantity Then '// check if value is less than or equals MinimumAllowedQuantity.
itm.BackColor = Color.Orange '// change BackColor.
Else
itm.BackColor = Color.LightGreen
End If
Next
End Sub
Do you want to add random item content from the ArrayList or just a specified item in the ArrayList?
>Also, I want to make that progressbar to work.
If using the code I recently posted, you could set the ProgressBar1.Maximum to myPresetFileSizeInBytes and change the value of the ProgressBar with iFileSize.
Before changing the value, check if ProgressBar1.Maximum > iFileSize, else set ProgressBar1.Maximum to iFileSize and change the value then.
This should only be needed towards the end of writing content to your file.
See if this helps.
1 Button
Imports System.IO
Public Class Form1
Private myFile As String = Nothing
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.Show()
Dim ofd As New OpenFileDialog : If ofd.ShowDialog = DialogResult.OK Then myFile = ofd.FileName
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
addContentToFile(4000, myFile)
End Sub
Private Sub addContentToFile(ByVal myPresetFileSizeInBytes As Integer, ByVal myFileToAddContentTo As String)
Dim myFileInfo As IO.FileInfo
Dim sTemp As String = "some content to add to the file." & vbNewLine
Dim iFileSize As Integer = 0 '// keeps track of file size.
Do Until iFileSize >= myPresetFileSizeInBytes '// loop Until the file size equals or is greater than the preset file size you need.
myFileInfo = New IO.FileInfo(myFileToAddContentTo) '// used to get file size.
iFileSize = CInt(myFileInfo.Length) '// set the file size.
'// write back file content after reading it and adding extra content.
File.WriteAllText(myFileToAddContentTo, File.ReadAllText(myFileToAddContentTo) & sTemp)
Loop
MsgBox("done")
End Sub
End Class
Use Application.Exit()
to exit your application whenever needed.
>There is other approach?
In your project's Properties/Application tab, locate the "Shutdown Mode:" and set it for "When last form closes".
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
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
See if this helps to save and load settings from a File.
2 CheckBoxes
Public Class Form1
Private myCoolSettingsFile As String = "C:\test.CFG" '// your settings.File.
'// use Region when needing to group together portions of code. makes it easy to minimize the entire section and not one Sub at a time.
#Region "========== SETTINGS ============"
Private Sub saveSettings()
Dim myCoolWriter As New IO.StreamWriter(myCoolSettingsFile)
With myCoolWriter
If CheckBox1.Checked Then .WriteLine("CheckBox1 is Checked") Else .WriteLine("CheckBox1 is NOT Checked")
If CheckBox2.Checked Then .WriteLine("CheckBox2 is Checked") Else .WriteLine("CheckBox2 is NOT Checked")
If CheckBox2.Checked Then .WriteLine("CheckBox2 is Checked") Else .WriteLine("CheckBox2 is NOT Checked")
End With
myCoolWriter.Close()
End Sub
Private Sub loadSettings()
If IO.File.Exists(myCoolSettingsFile) Then
Dim arTemp() As String = IO.File.ReadAllLines(myCoolSettingsFile) '// read all lines into arrays.
Try '// not to crash on startup.
If arTemp(0) = "CheckBox1 is Checked" Then CheckBox1.Checked = True '// check line 1.
If arTemp(1) = "CheckBox2 is Checked" Then CheckBox2.Checked = True '// check line 2.
If arTemp(2) = "CheckBox2 is Checked" Then CheckBox2.Checked = True '// check line 2.
If arTemp(3) = "CheckBox2 is Checked" Then CheckBox2.Checked = True '// check line 2.
Catch ex As Exception
MsgBox("If you added new code to save and did not run the app. before you added code to load, you will get this message since the line you are checking for on startup has not been saved yet.", MsgBoxStyle.Information, "codeorder vb.net tip")
End Try
End If
End Sub
#End Region
Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) …
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
If CType(Form1.Controls.Item("CheckBox" & texton), CheckBox).Checked = True Then
MsgBox("done")
End If
See if this helps to change BackColor of items in a ListView.
For Each itm As ListViewItem In ListView1.Items '// loop thru all items.
If itm.Text <= CStr(5) Then '// check if value is less than or equals 5. CStr = Convert to String, since using an Integer.
itm.BackColor = Color.Orange '// change BackColor.
Else
itm.BackColor = ListView1.BackColor '// if not <=5, set itm BackColor to ListView.BackColor.
End If
Next
If a .SubItem, replace # with the Column #. If itm.SubItems(#).Text <= CStr(5) Then
You should have no trouble adding a MsgBox as needed.
You could use a TabControl and remove the TabPages Headers.
http://dotnet.mvps.org/dotnet/faqs/?id=tabcontrolremoveheaders&lang=en
Then use your btnNext/btnPrevious to scroll through the TabPages.
'// Next Tab.
With TabControl1 '// if not last TabPage, go to next.
If Not .SelectedIndex = .TabPages.Count - 1 Then .SelectedIndex += 1
End With
'// Previous Tab.
With TabControl1 '// if not first TabPage, go to previous.
If Not .SelectedIndex = .TabPages.Count - 1 Then .SelectedIndex += 1
End With
Removing the TabControl TabPages Headers is probably the best solution since it gives you full access for editing each TabPage while in Designer.
See if this helps to save and load a image, then use it as BackgroundImage of a Form.
Public Class Form1
Private myFile As String = "C:\test.txt" '// your file to save/load image path.
Private myLoadedImageFile As String = "" '// used to store FullPath of image loaded.
Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
IO.File.WriteAllText(myFile, myLoadedImageFile) '// Save FilePath of image.
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
If IO.File.Exists(myFile) Then '// check if file containing FullPath of image exists.
If IO.File.Exists(IO.File.ReadAllText(myFile)) Then '// read file and check if image exists.
myLoadedImageFile = IO.File.ReadAllText(myFile) '// store image.
Me.BackgroundImage = Image.FromFile(myLoadedImageFile) '// change BackgroundImage.
End If
End If
Me.Visible = True
Dim ofd As New OpenFileDialog
With ofd
.Title = "Select a image to use as Background..."
If .ShowDialog = DialogResult.OK Then
myLoadedImageFile = .FileName '// store FullPath to use for when saving.
Me.BackgroundImage = Image.FromFile(.FileName) '// add image as BackgroundIMage to Form.
End If
End With
End Sub
End Class
Using my previously posted code, replace If itm.Text = TextBox1.Text Then
with If itm.SubItems(6).Text = TextBox1.Text Then
, or whichever .SubItems(#) is related to the specific column.
Does your ListView have Columns and if so, which column would Me.TextBox6.Text
have to be compared to?
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
See if this helps to locate and select item in ListView.
For Each itm As ListViewItem In ListView1.Items '// loop thru all items.
If itm.Text = TextBox1.Text Then
itm.Selected = True '// select.
itm.EnsureVisible() '// make sure item is visible.
Exit For '// exit loop since item located.
End If
Next
For future references, please start a new thread for any "non related" questions.
Since you have already provided information, even a "cute" image:D that looks very nice by the way, see if this helps.
Public Class Form1
Private iPercentage As Integer = 0 '// used to get percentage of correct answers.
Private iCorrectAnswer As Integer = 0 '// used to add up random # and selected # to get the correct total.
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
iPercentage = 0 '// reset.
'// send appropriate controls to the Sub to get results.
getCoolUserTotal(Txtbox_AddRan1, Txtbox_AddUser1, TxtBox_CorrectAns1, TxtBox_UserAns1, PitBox_mark1)
getCoolUserTotal(Txtbox_AddRan2, Txtbox_AddUser2, TxtBox_CorrectAns2, TxtBox_UserAns2, PitBox_mark2)
getCoolUserTotal(Txtbox_AddRan3, Txtbox_AddUser3, TxtBox_CorrectAns3, TxtBox_UserAns3, PitBox_mark3)
'// etc..
Lbl_TotalMark.Text = iPercentage & "%" '// display pecentage of correct answers.
End Sub
Private Sub getCoolUserTotal(ByVal txtForRandomNumber As TextBox, ByVal txtForSelectedNumber As TextBox, ByVal txtForCorrectAnswer As TextBox, ByVal txtForUserAnswer As TextBox, ByVal pbForImage As PictureBox)
'// get correct total of random # and selected #.
iCorrectAnswer = CInt(txtForRandomNumber.Text) + CInt(txtForSelectedNumber.Text) '// CInt = Convert to Integer since .Text is a String.
'// check user total with the correct answer.
If txtForUserAnswer.Text = CStr(iCorrectAnswer) Then '// if correct answer.
pbForImage.Image = My.Resources.tick '// set image.
iPercentage += 10 '// only add to percentage if correct answer.
Else '// if wrong answer.
pbForImage.Image = My.Resources.cross '// set image.
End If
'// display correct answer.
txtForCorrectAnswer.Text = CStr(iCorrectAnswer) '// CStr = Convert to String since .Text is a String.
End Sub
End Class
1. Give your Array a different Variable Name for each Array declared.
Dim arMyCoolTextBoxesArray() As TextBox = {TextBox1, TextBox2, TextBox3}
Dim arMyOtherCoolTextBoxesArray() As TextBox = {TextBox4, TextBox5, TextBox6}
2. Use the same Array and just change the values.
Dim arMyCoolTextBoxesArray() As TextBox = {TextBox1, TextBox2, TextBox3}
For i As Integer = 0 To arMyCoolTextBoxesArray.Length - 1
arMyCoolTextBoxesArray(i).Text = ComBox_ChooseNum.Text
Next
arMyCoolTextBoxesArray = {TextBox4, TextBox5, TextBox6}
For i As Integer = 0 To arMyCoolTextBoxesArray.Length - 1
arMyCoolTextBoxesArray(i).Text = ComBox_ChooseNum.Text
Next
3. Skip the entire Array and set values in each TextBox once it is located by the # at the end of a TextBox's .Name.
'// my TextBoxes are named TextBox1, TextBox2, TextBox3, etc..
For i As Integer = 1 To 10
CType(Me.Controls("TextBox" & i), TextBox).Text = ComBox_ChooseNum.Text
Next