>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.
>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
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
Do you want to add random item content from the ArrayList or just a specified item in the ArrayList?
Use the _TextChanged event and set the value as it is being typed in.
Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
'// check if numeric, then set new value for myCustomerTotalSpendingAllowed.
If IsNumeric(TextBox1.Text) Then myCustomerTotalSpendingAllowed = CDbl(TextBox1.Text)
End Sub
>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.
:D, my apologies for the extra code lines for CheckBox2 and some incorrect comments for which line # of the file is being read.
Late night programming is not my specialty.
Glad I could help otherwise.:)
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.
razree, please start your own thread for your "own" questions.
If you need help doing so, send me a private message.
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
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
Public Sub navigaterecords(ByVal lvItemIndex As Integer)
With ListView1.Items(lvItemIndex)
txtMed_ID.Text = .SubItems(0).Text
txtMed_name.Text = .SubItems(1).Text
txtfname.Text = .SubItems(2).Text
txtMname.Text = .SubItems(3).Text
txtDept_ID.Text = .SubItems(4).Text
cboxgender.Text = .SubItems(5).Text
txtDOB.Text = .SubItems(6).Text
txtMed_Type.Text = .SubItems(7).Text
End With
End Sub
See if this helps.
Public Sub navigaterecords(ByVal lvItemIndex As Integer)
With ListView1.Items(lvItemIndex)
MsgBox(.SubItems(0).Text) '// for testing.
End With
End Sub
'// First.
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
navigaterecords(0)
End Sub
'// Last.
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
navigaterecords(ListView1.Items.Count - 1)
End Sub
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
See if this helps.
2 Forms(1 ProgressBar on Form2)
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.Visible = True '// for testing. Displays Form, then displays Form2.
Form2.ShowDialog()
End Sub
Public Sub startCoolProgressBarCode(ByVal myCoolProgressBar As ProgressBar)
'// Add ProgressBar code here.
'//------- For testing purposes.
For i As Integer = 0 To myCoolProgressBar.Maximum
myCoolProgressBar.Value = i
Threading.Thread.Sleep(50) '// pauses entire app.. not recommended, just used for testing.
Next '---------\\
Form2.Close() '// Close Form2 once done.
End Sub
End Class
Public Class Form2
Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'// Disable the ControlBox and set the Form to .Visible before calling the Sub on Form1.
Me.ControlBox = False : Me.Visible = True
Form1.startCoolProgressBarCode(Me.ProgressBar1)
End Sub
End Class
Set .WindowState of a Form to Maximized/Minimized/Normal?
Me.WindowState = FormWindowState.Maximized
See if this helps.
'// paste in New Project and click to move Form.
'//-- Panel1 and PictureBox1 can be uncommented to use the same Events.
'//-- to use only a Panel, PictureBox, or any other control, just add the appropriate code for each event.
Public Class Form1
Private allowCoolMove As Boolean = False
Private myCoolPoint As New Point
Private Sub Form1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) _
Handles Me.MouseDown ', Panel1.MouseDown, PictureBox1.MouseDown
allowCoolMove = True '// enable move.
myCoolPoint = New Point(Cursor.Position.X - Me.Location.X, Cursor.Position.Y - Me.Location.Y) '// get coordinates.
End Sub
Private Sub Form1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) _
Handles Me.MouseMove ', Panel1.MouseMove, PictureBox1.MouseMove
If allowCoolMove = True Then
Me.Location = New Point(Cursor.Position.X - myCoolPoint.X, Cursor.Position.Y - myCoolPoint.Y) '// set coordinates.
End If
End Sub
Private Sub Form1_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) _
Handles Me.MouseUp ', Panel1.MouseUp, PictureBox1.MouseUp
allowCoolMove = False '// disable move.
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.FormBorderStyle = Windows.Forms.FormBorderStyle.None
End Sub
End Class
Try this for "out of bounds exception".
For x = 0 To numbers.Length - 1
When using .Length or .Count, it starts at 1 not 0.
Since you are looping from "0", then subtract 1 from .Length to get a even amount of loops.
As for the bubble issue, good luck.
Loading a modal form, just like loading a MsgBox, it will stop all running code until that form is closed.
Why not have your code within your modal Form and run the code right after you load this Form?
Use the _TextChanged event of the RichTextBox.
Private Sub RichTextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RichTextBox1.TextChanged
Label1.Text = (RichTextBox1.MaxLength - RichTextBox1.TextLength).ToString
End Sub
An ArrayList is nothing more than a ListBox.
For example, adding an item to a ListBox, you use: ListBox1.Items.Add("test item")
... and adding an item to an ArrayList, you just use: myArrayList.add("test item")
without the".Items".
See if this helps.
1 Button
Public Class Form1
Private myFile As String = "C:\test.txt" '// your file.
Private arlCoolArrayList As New ArrayList '// ArrayList used to load file lines/etc..
Private rndArrayListItems As New Random '// for randomizing.
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
If IO.File.Exists(myFile) Then arlCoolArrayList.AddRange(IO.File.ReadAllLines(myFile)) '// Load File Lines into Array List.
'// add some items yourself if needed.
arlCoolArrayList.Add("new item added to ArrayList")
arlCoolArrayList.Add("add another, just because you can :D")
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
rndArrayListItems = New Random '// setting it as New Random usually returns a more random #.
'// randomize from 0 to .Count, since using 0 to .Count-1 will not consider the last item.
Dim iRandomNumber As Integer = rndArrayListItems.Next(0, arlCoolArrayList.Count)
If Not arlCoolArrayList.Count = 0 Then ' check if items in ArrayList.
MsgBox(arlCoolArrayList(iRandomNumber)) '// Display result.
End If
'arlCoolArrayList.Remove("new item added to ArrayList") '// remove item by String.
'// Or...
'arlCoolArrayList.RemoveAt(iRandomNumber) '// remove item by Index.
End Sub
End Class
How are you loading employee names and their id numbers? From file? Database?
>There is a way to generate a more random string, something new everytime it add more info?
You could load a file with thousands of random lines into an ArrayList and randomly select an item from the ArrayList to add to your file content and if needed, inject characters/.Substrings from that random item all throughout your file.
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
Since you already have most of the info in this thread to accomplish your goal, I will send you a private message and help you organize the code already provide to get you a solution. Reason is, kind of pointless to overload a permanent thread with similar info and private messages can be deleted.
Check out this link, it might have the info you are looking for.
I converted the code provided in that link from c# to vb.net, but I personally do not have any experience with vb.net and XSLT.
Dim processor As Xml.Xsl.XslCompiledTransform = New Xml.Xsl.XslCompiledTransform(True)
Wish I could be of further help, good luck.
>There is a way to control it?
Why not? Save file every so often, check for file size and if not at your standard, add more content and save again.
Dim myCoolFileInfo As New IO.FileInfo("C:\test.txt") '// your file.
MsgBox(CInt(myCoolFileInfo.Length).ToString("#,###,###,###,###") & " bytes") '// file size.
Not quite clear what you are trying to do with the numbers() and numNumbers, but using the ReDim Statement should help.
Private numbers() As Double '// changed to Double since TextBox allows ".".
Private numNumbers As Integer = 0
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If Not TextBox1.Text = "" Then
ListBox1.Items.Add(TextBox1.Text)
ReDim Preserve numbers(numNumbers)
numbers(numNumbers) = CDbl(TextBox1.Text)
numNumbers += 1
End If
End Sub
Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged
'// For testing.
MsgBox(numbers(ListBox1.SelectedIndex).ToString) '// display the number added to your numbers Array.
End Sub