Feb 8, 2015 06:17 PM
(This post was last modified: Feb 8, 2015 06:18 PM by SIM-2137258.)
Source Code :
Code Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
ComboBox1.SelectedItem = "1"
ComboBox2.SelectedItem = "99"
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim Characters As String = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890"
Dim Result As String
Dim Casual As New Random
For i = 0 To Casual.Next(ComboBox1.SelectedItem, ComboBox2.SelectedItem)
Result += Characters(Casual.Next(0, Characters.Length - 1))
Next
TextBox1.Text = Result
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
My.Computer.Clipboard.SetText(TextBox1.Text)
End Sub
End Class
I'm unsure as to what you're looking for from the community. This release isn't really worth releasing as an application in my opinion. However, I'm not going to hate on your project like everyone else probably will. Instead, I wanted to give you a few coding tips to make your application more efficient.
To start things off, I'd like to talk about your use of numbers in a ComboBox. From the looks of things, you manually typed each number from 1 to 99 into the Items property of both ComboBoxes. Instead of using ComboBoxes here, look into the NumericUpDown control. You won't need to type in all of your possible outcomes. You'll just need to set the minimum and maximum properties to whatever you'd like.
Keep in mind that every line of code takes time to complete. Therefore, it would be more efficient to declare your variables within your class scope. This way, you're not taking the time to redeclare a variable each time your buttons are clicked. Consider the same thing when initializing your variables (assigning them a value). For example, instead of assigning a value to Characters each time the button is clicked, just assign it a value on the Form_Load event. This way you only set the value once.
Your For loop is fine, but try using a StringBuilder instead of repeatedly adding characters to your string.
Hopefully this will help you to optimize your application as well as help you in future projects.
- Hawk
🤝
(Feb 8, 2015 06:40 PM)Hawk HF Wrote: I'm unsure as to what you're looking for from the community. This release isn't really worth releasing as an application in my opinion. However, I'm not going to hate on your project like everyone else probably will. Instead, I wanted to give you a few coding tips to make your application more efficient.
To start things off, I'd like to talk about your use of numbers in a ComboBox. From the looks of things, you manually typed each number from 1 to 99 into the Items property of both ComboBoxes. Instead of using ComboBoxes here, look into the NumericUpDown control. You won't need to type in all of your possible outcomes. You'll just need to set the minimum and maximum properties to whatever you'd like.
Keep in mind that every line of code takes time to complete. Therefore, it would be more efficient to declare your variables within your class scope. This way, you're not taking the time to redeclare a variable each time your buttons are clicked. Consider the same thing when initializing your variables (assigning them a value). For example, instead of assigning a value to Characters each time the button is clicked, just assign it a value on the Form_Load event. This way you only set the value once.
Your For loop is fine, but try using a StringBuilder instead of repeatedly adding characters to your string.
Hopefully this will help you to optimize your application as well as help you in future projects.
- Hawk
🤝
Thank you very much for your constructive feedback.
(Feb 8, 2015 06:40 PM)Hawk HF Wrote: I'm unsure as to what you're looking for from the community. This release isn't really worth releasing as an application in my opinion. However, I'm not going to hate on your project like everyone else probably will. Instead, I wanted to give you a few coding tips to make your application more efficient.
To start things off, I'd like to talk about your use of numbers in a ComboBox. From the looks of things, you manually typed each number from 1 to 99 into the Items property of both ComboBoxes. Instead of using ComboBoxes here, look into the NumericUpDown control. You won't need to type in all of your possible outcomes. You'll just need to set the minimum and maximum properties to whatever you'd like.
Keep in mind that every line of code takes time to complete. Therefore, it would be more efficient to declare your variables within your class scope. This way, you're not taking the time to redeclare a variable each time your buttons are clicked. Consider the same thing when initializing your variables (assigning them a value). For example, instead of assigning a value to Characters each time the button is clicked, just assign it a value on the Form_Load event. This way you only set the value once.
Your For loop is fine, but try using a StringBuilder instead of repeatedly adding characters to your string.
Hopefully this will help you to optimize your application as well as help you in future projects.
- Hawk
🤝
Wouldn't it be better to make Characters a constant?
|