|
-
May 26th, 2011, 08:47 PM
#1
Thread Starter
New Member
[RESOLVED] Newb and VB
I'm trying to make a small app based on some physics work, so basically I want some way of storing data, will be constant (just dont know how to get it there! ) and then displaying it using a drop down box on a form.
I thought I could use a dataset, the data I need to store is; BindingEnergy, NucleonNumber, Element and Symbol. The drop down box will get values of Symbol's and once selected will automatically show below the drop down box; the full Element name, Binding Energy and Nucleon Number.
Although I just don't know how to do it, so I'm hoping someone can help, I know the jist of things but I keep getting errors when I try things, although I wasn't hopefully anyway!
Thanks in advance,
Ollie
-
May 26th, 2011, 09:33 PM
#2
Member
Re: Newb and VB
i was about to type you a detailed message about how you could do this, but if you're completely new to VB its impossible to explain everything just by typing. All i can say is watch some beginner YouTube videos because it takes an understanding of programming and how VB.net works before you can start.
-
May 26th, 2011, 10:31 PM
#3
Re: Newb and VB
A dataset would need to get data from somewhere. The data in the dataset only resides in memory, so when the program ends, the dataset is destroyed. If you are talking about persisting data after the application ends, then you will need something more. You have many options, though, and it is hard to say which would be best.
The most versatile option would be a database. This would work well for any amount of data, but it takes more knowledge than any other technique.
Another option would be an XML file. Datatables and datasets have methods to read and write XML files, which are text files that follow XML format rules. Being text files, they can be read and edited by any text editor, such as Notepad. The drawback to using XML is that the files could easily become very large, depending on how much data you have. Still, XML is easier to learn than a database at the expense of not managing large sizes well, and having less powerful features.
A third option would be My.Settings, which would be about the easiest thing you could do, but is almost certainly a bad idea, unless the amount of data you are talking about is much smaller than I suspect it is.
My usual boring signature: Nothing
 
-
May 27th, 2011, 03:15 AM
#4
Thread Starter
New Member
Re: Newb and VB
Thanks both for your answers, I'm okay if I'm explained something, I've followed a few tutorials and made a couple of programs and made my own arduino controller program.
I've got the start of this physics program, this is just one 'sub' program to do with binding energy.
I only require about 30/40 entries with 4 bits of data (BindingEnergy, NucleonNumber, Element and Symbol).
@Shaggy I think the last two are my best options and if that is little enough data to warrant the easiest option of My.Settings then I'd like to know how to do that! 
Ollie
-
May 27th, 2011, 09:22 AM
#5
Re: Newb and VB
Search around this forum for My.Settings and you should get lots of examples. The easiest thing to do is to go into Project|Properties and take a look at the settings tab. What you can do on that tab is set a bunch of settings. These act like persistent variables in your program. If you add a setting of type string with the name "Blue", then you can use it in code with:
My.Settings.Blue = "some string"
You also have the means to save the settings explicitly with something like My.Settings.Save (I didn't look it up, but it is something like that). However, when your program closes, it should save the settings automatically.
From the settings tab on Project|Properties, you can add as many settings as you'd like, and you have a good number of data types you can use for those settings. You can actually use any data type you want, but if you go beyond the ones found on the pick list on that form then you will have to do a bit more work to save and recover them.
My usual boring signature: Nothing
 
-
May 27th, 2011, 06:54 PM
#6
Thread Starter
New Member
Re: Newb and VB
Thanks again for your help, this is what I tried and obviously failed but hopefully you can see what I'm trying to achieve!
In settings I've made two settings, one called 'H' with value 'Hydrogen,1,0' and the other called 'He' with value 'Helium,4,7.1'.
The vb code is:
Code:
Public Class Form4
Dim slction As String
Dim selectedel As String
Private Sub Form4_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim elesym As String = "H,He"
Dim drpdwn As String() = elesym.Split(New Char() {","c})
For Each Me.slction In drpdwn
ComboBox1.Items.Add(slction)
Next slction
' When working add; ComboBox1.SelectedIndex = 0
End Sub
Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
selectedel = ComboBox1.Text
' TextBox to test
TextBox1.Text = selectedel
' We want to split this input string
Dim element As String = My.Settings.selectedel()
' Split string based on commas
Dim words As String() = element.Split(New Char() {","c})
' Display them
RichTextBox1.Text = words(0)
RichTextBox2.Text = words(1)
RichTextBox3.Text = words(2)
End Sub
End Class
But obviously the code in red throws back an error but whats a way I can achieve what I want using the drop down box to select the setting and display the comma split value's in the RichTextBox's?
If I change 'selectedel' to either 'H' or 'He' the rest of the code works fine (displays the split value in each individual box).
Hope that all makes sense,
Ollie
Last edited by Chalky99; May 27th, 2011 at 06:57 PM.
-
May 27th, 2011, 07:07 PM
#7
Thread Starter
New Member
Re: Newb and VB
Just made it work by replace this line:
Code:
Dim element As String = My.Settings.selectedel()
with this code, works as expected, just not very neat code imo!
Code:
If selectedel = "He" Then
element = My.Settings.He()
ElseIf selectedel = "H" Then
element = My.Settings.H()
End If
Ollie
-
May 27th, 2011, 10:11 PM
#8
Re: Newb and VB
Yeah, I suppose it might not appear so neat, but it is what it is. One alternative would be to take all settings at form load and put them into a Dictionary(of String, String). The key would be the name, and the value would be the setting value. It would look something like this:
Private elDict as New Dictionary(Of String,String)
'In form load, or the form constructor:
elDict.Add("He", My.Settings.He)
elDict.Add("H",My.Settings.H)
...etc.
You would then be able to access any of the items using a line like this:
Dim words As String() = elDict(selectedel).Split(New Char() {","c})
When passed a valid key(selectedel), the dictionary returns the value, which is then being split using the code you have. Note that this will fail if you pass in a value in selectedel that is not already in the dictionary, because it will return Nothing, and you can't call .Split on that. In your case, this shouldn't be an issue, as you have complete control over what goes into the dictionary and what goes into selectedel.
My usual boring signature: Nothing
 
-
May 28th, 2011, 04:46 AM
#9
Thread Starter
New Member
Re: Newb and VB
Worked a treat! Thanks a lot,
Ollie
-
May 28th, 2011, 05:04 AM
#10
Fanatic Member
Re: Newb and VB
 Originally Posted by stagnit
i was about to type you a detailed message about how you could do this, but if you're completely new to VB its impossible to explain everything just by typing. All i can say is watch some beginner YouTube videos because it takes an understanding of programming and how VB.net works before you can start.
My advice to you is learn C# instead of VB.net
-
May 28th, 2011, 09:13 AM
#11
Re: [RESOLVED] Newb and VB
My advice to you is to ignore that advice from x-ice unless you have good reason not to.
There has long been a belief that VB is a toy language, and that has been extended to .NET. This perpetuates in the pay scale, where C# developers are paid, on average, somewhat higher than VB developers. This is nuts, since MS deliberately converged the two languages beginning with the 2005 version. The two compile to the same IL, and there are no feature differences between the two that are worth anything. Each one does a few minor things better than the other, but VB is a VASTLY superior language for most people. After all, any good typist will be considerably more productive in VB, which primarily uses text, over any of the C-based languages that make such heavy use of the tendon killing symbol keys (and especially heavy use of Shift-symbol keys, such as the curly braces). Everything you are taught to avoid in any typing class is what C-based languages make the most heavy use for. C-style languages are easiest for crappy hunt-and-peck typists, which is a dieing breed in our increasingly computerized society.
C-style languages are archaic for other reasons, too. For example, they are case sensitive, which is just a stupid design. A case sensitive language means that the variable MyVariable is different from myvariable, and both are different from myVariable. That means that you can have MANY different variables with the exact same characters, but with different cases. No sane person would use two variables that only differ by case, as it would be a maintenance nightmare, so why did C use this style? C uses the style because C is so old that the original compilers didn't have enough reserve computing power to correct cases like VB can. Case sensitivity only persists because of people worshipping at the alter of past practices because they are old, not because they are useful. It's an archaic holdover foisted on the coding community by the necessity of a day that no longer exists. It would be like all programs being requires to fit into 64K just because that's all the early PCs had.
Another example of this is the semi-colon that has to terminate every line in a c-style language. This causes more headaches for people than probably anything else in those languages. It isn't necessary. In VB, the line ended when the line ended. If you wanted to continue the line to the next line you could use the line continuation character, and even that has been dispensed with these days. But the c-style languages are still tied to that superfluous character. It's an indefensibly bad design, but they can't break free of it.
And on I could go. It is my contention that the C-syntax languages persist because they are used by a bunch of geeks who are so insecure that they need to make coding extra-incomprehensible to bolster their dubious claim to self-worth.
My usual boring signature: Nothing
 
-
May 28th, 2011, 04:36 PM
#12
Thread Starter
New Member
Re: [RESOLVED] Newb and VB
Well I thought about getting into C# but thought 'what is the point' when VB is easier and will make the same program but for me, a lot quicker and easier!
Is VB and C# a bit like blu-ray and hd-dvd with VB winning? lol
-
May 29th, 2011, 12:53 PM
#13
Fanatic Member
Re: [RESOLVED] Newb and VB
Any good software engineer will know that productivity shouldn't be measured be the amount of code someone can type in a given time period.
Also in the UK c# developers earn on average £5000 a year more than vb.net developers
-
May 29th, 2011, 10:00 PM
#14
Re: [RESOLVED] Newb and VB
 Originally Posted by x-ice
Any good software engineer will know that productivity shouldn't be measured be the amount of code someone can type in a given time period.
And any rational human will know that the person who can do the same job in half the time is going to be more productive.
The pay differential exists to some extent in the US, as well. That's a real point, but it is based on myth rather than reality, and that myth should be stamped out. On the other hand, who am I to argue the point? I work for well below the industry average for any language, and do so for reasonably good reasons. If you are going to chase dollars, then you should learn C# until management morons figure out that they are being played.
My usual boring signature: Nothing
 
-
May 30th, 2011, 04:50 AM
#15
Fanatic Member
Re: [RESOLVED] Newb and VB
I'll make one last point that will support my arguement. Option Explicit set to ON makes sure that all variables are explicitly declared. This is ON by default, but the whole idea that you CAN turn it off is absurd. Why would the designers of vb.net allow this? The only thing it encourages is bad programming.
And that (bad programming) is why vb.net developers do not get paid as much, because they generally are not as skilled as c# developers.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|