News: 11 March 2016 - Forum Rules
Current Moderators - DarkSol, KingMike, MathOnNapkins, Azkadellia, Danke

Author Topic: Stupid issues with VB.NET  (Read 7009 times)

InfamousKnight

  • Sr. Member
  • ****
  • Posts: 321
    • View Profile
Stupid issues with VB.NET
« on: November 29, 2012, 05:23:26 pm »
Say if I wanted to put an array in a struct:
I have:
Code: [Select]
structure struct
    Dim names(5) as string
end structure
that ^ would give you an error saying: array cannot be initialized in structure..
That's not an issue in C/C++..

To fix this, I have to use this stupid method:
Code: [Select]
structure struct
    Dim names() as string
end structure
Dim struct as struct
ReDim struct.names(5)
struct.names(0) = "John"
struct.names(1) = "King"
struct.names(2) = "Queen"
What does that ReDim statement even do?

Say if I want an array of images:
Code: [Select]
Dim pics(5) as Picturebox
for i as integer = 0 to 5
pics(i) = new Picturebox
end for

Well, that's apparently not good enough:
Code: [Select]
Dim obj as picturebox
Dim pics(5) as Picturebox
obj = new picturebox
obj.imagelocation = "FilePath"
pics(0) = obj
Yeah, so you need 2 classes of the same type in order for this to work.. Idk how that makes sense but that's just the way it is.

However, I never tried making a 2D array of objects in C++ so I wouldn't be sure on this.

snarfblam

  • Submission Reviewer
  • Hero Member
  • *****
  • Posts: 590
  • CANT HACK METROID
    • View Profile
    • snarfblam
Re: Stupid issues with VB.NET
« Reply #1 on: November 29, 2012, 05:45:18 pm »
What exactly are you trying to do? VB.NET (and any other .NET language) doesn't support arrays embedded in structures. While it can be inconvenient, there is a reason why it's done that way, and I've never been unable to find a workaround.

Based on the code you've shown, you could write a very simple helper method.

Code: [Select]
structure struct
    Dim names() as string
   
    Public Function MakeNew() As struct
        Dim result As New struct
        result.names = new String(5) {}
    End Function
end structure

The ReDim is the command to create the array. The reason you can't have an array created automatically in a structure is because any structure can be instantiated without calling a constructor (Sub New), and the constructor is what actually creates the array.

The other thing you have to ask yourself is whether there's a reason that you're using a structure instead of a class. What you want to do is perfectly valid in a class, since instantiating a class always runs a constructor. The way classes work also tends to be a lot more intuitive than the way structs work. You generally want to stick with classes unless you have a specific reason for wanting to use a structure.

Code: [Select]
Class BetterIdea
    Dim Result(5) As String
End Class

I have no idea what the problem is that you're trying to demonstrate in your last two code listings. That you have to create a temporary variable to initialize an object before inserting it into an array?

InfamousKnight

  • Sr. Member
  • ****
  • Posts: 321
    • View Profile
Re: Stupid issues with VB.NET
« Reply #2 on: November 29, 2012, 06:35:02 pm »
So a string is a class? I've known that but never knew that I can't place a class in a struct.

snarfblam

  • Submission Reviewer
  • Hero Member
  • *****
  • Posts: 590
  • CANT HACK METROID
    • View Profile
    • snarfblam
Re: Stupid issues with VB.NET
« Reply #3 on: November 29, 2012, 09:07:23 pm »
Yes, System.String is a class, but I don't think that's actually related to your problem.

Maybe you're being thrown off by the semantics. In C++ structs and classes are basically the same thing. In VB.NET they are pretty different. If you're not clear on the differences you should probably read up on the difference between value types (structures) and reference types (classes).

Rhys

  • Hero Member
  • *****
  • Posts: 706
    • View Profile
    • CN
Re: Stupid issues with VB.NET
« Reply #4 on: November 30, 2012, 02:16:57 am »
Do you really need value type semantics? Classes are way more flexible in .NET than Structs. You really need a special reason to use Structs over Classes when you're coding in .NET.

InfamousKnight

  • Sr. Member
  • ****
  • Posts: 321
    • View Profile
Re: Stupid issues with VB.NET
« Reply #5 on: November 30, 2012, 04:16:23 pm »
You really need to be a n00b when programming in .NET! I kinda don't like knowing this n00bish language..

LostTemplar

  • Hero Member
  • *****
  • Posts: 906
    • View Profile
    • au-ro-ra.net
Re: Stupid issues with VB.NET
« Reply #6 on: November 30, 2012, 05:12:11 pm »
Then why are you using it?

InfamousKnight

  • Sr. Member
  • ****
  • Posts: 321
    • View Profile
Re: Stupid issues with VB.NET
« Reply #7 on: November 30, 2012, 05:56:26 pm »
Then why are you using it?

Mostly for graphical frontends.

snarfblam

  • Submission Reviewer
  • Hero Member
  • *****
  • Posts: 590
  • CANT HACK METROID
    • View Profile
    • snarfblam
Re: Stupid issues with VB.NET
« Reply #8 on: November 30, 2012, 07:16:02 pm »
You really need to be a n00b when programming in .NET! I kinda don't like knowing this n00bish language..
What does this even mean? One moment you're having trouble figuring it out, the next it's a noob language?

If you don't like VB because it isn't C++ then just use C++.

KaioShin

  • RHDN Patreon Supporter!
  • Hero Member
  • *****
  • Posts: 5697
    • View Profile
    • The Romhacking Aerie
Re: Stupid issues with VB.NET
« Reply #9 on: December 01, 2012, 04:29:22 am »
You really need to be a n00b when programming in .NET! I kinda don't like knowing this n00bish language..

You sir, ARE a noob in programming. Your struggle with even the most basic programming concepts in your various threads proves this. You should be careful about spewing random crap you picked up somewhere on the internet without understanding it. No one said anything until now since you are trying to learn and everyone is starting somewhere, but it's time for a reality check now.
All my posts are merely personal opinions and not statements of fact, even if they are not explicitly prefixed by "In my opinion", "IMO", "I believe", or similar modifiers. By reading this disclaimer you agree to reply in spirit of these conditions.

Rhys

  • Hero Member
  • *****
  • Posts: 706
    • View Profile
    • CN
Re: Stupid issues with VB.NET
« Reply #10 on: December 01, 2012, 06:02:57 am »
I think you just need to pick a language you like the most and go for it. Don't heed other people's words too much about which language is better than another, just code in whatever language you're most comfortable with.

Once you're familiar enough with the concepts, you can start learning 'real' languages.

InfamousKnight

  • Sr. Member
  • ****
  • Posts: 321
    • View Profile
Re: Stupid issues with VB.NET
« Reply #11 on: December 01, 2012, 09:12:11 am »
Would you guys use VB for hacking? :P

I suppose this thread became a joke ^_^ I always loved making fun of those languages for n00bs. I could say something worse then "n00bs" but that can be risky for a ban.

KaioShin

  • RHDN Patreon Supporter!
  • Hero Member
  • *****
  • Posts: 5697
    • View Profile
    • The Romhacking Aerie
Re: Stupid issues with VB.NET
« Reply #12 on: December 01, 2012, 09:20:14 am »
Any language can be used for hacking, one of the most powerful font hacking tools, FEIDIAN, is written in PHP.
All my posts are merely personal opinions and not statements of fact, even if they are not explicitly prefixed by "In my opinion", "IMO", "I believe", or similar modifiers. By reading this disclaimer you agree to reply in spirit of these conditions.

Nightcrawler

  • Hero Member
  • *****
  • Posts: 5768
    • View Profile
    • Nightcrawler's Translation Corporation
Re: Stupid issues with VB.NET
« Reply #13 on: December 01, 2012, 12:05:02 pm »
It's also a bit ignorant to declare Visual Basic .NET as a 'noob' language. Since the .NET version switch 10 years ago, it's every bit as capable as C# or any other .NET language. It's simply syntactic flavoring over .NET. We're not talking about QBasic or the 90's versions of Visual Basic, which is entirely different. I would advise doing some reading on the subject before commenting further.

The 'joke' is completely lost amongst those knowledgeable of the subject.
TransCorp - Over 20 years of community dedication.
Dual Orb 2, Wozz, Emerald Dragon, Tenshi No Uta, Glory of Heracles IV SFC/SNES Translations

InfamousKnight

  • Sr. Member
  • ****
  • Posts: 321
    • View Profile
Re: Stupid issues with VB.NET
« Reply #14 on: December 01, 2012, 02:02:04 pm »
I just think of low level languages as powerful languages while high level languages are those slow languages.. VB is very high leveled which just means its easy to understand by just looking at the code. I believe its so high leveled that I can figure out the code by just looking it and not even know what programming is. On the other hand, with ASM, that's not the case. Who would figure out what mov ah,09 even do? I hear that mov doesn't move the value 09 into ah. It really copies it.

Anyways, lock this thread somebody!

relminator

  • Jr. Member
  • **
  • Posts: 27
    • View Profile
Re: Stupid issues with VB.NET
« Reply #15 on: December 03, 2012, 05:34:37 am »
Yes, MOV does not move but copy.  As someone who codes in C++, BASIC and x86ASM, my take on this issue is: "Just use what you think is best for this project".

I use C++ for my biggest project which requires speed, BASIC(freebasic) for quick prototyping and ASM for some esoteric stuff like a 256byte demo which is quite a bitch to read.  Hell, I couldn't even read it at a glance now and it was my code! lol

http://pouet.net/prod.php?which=24821


Garoth Moulinoski

  • Hero Member
  • *****
  • Posts: 6290
  • Disliking that smoke.
    • View Profile
    • My Stuff including Super Smash Karts.
Re: Stupid issues with VB.NET
« Reply #16 on: December 03, 2012, 11:13:54 am »
Any language can be used for hacking, one of the most powerful font hacking tools, FEIDIAN, is written in PHP.

Holy $^%&. I don't know why that amazes me, but it just does. Pretty cool though.

Quote
I just think of low level languages as powerful languages while high level languages are those slow languages.. VB is very high leveled which just means its easy to understand by just looking at the code. I believe its so high leveled that I can figure out the code by just looking it and not even know what programming is. On the other hand, with ASM, that's not the case. Who would figure out what mov ah,09 even do? I hear that mov doesn't move the value 09 into ah. It really copies it.

Anyways, lock this thread somebody!

I think you're twisting the purposes for high-level languages. The reason why you want to use a high-level language is precisely because it's easier to understand the code. Yes, depending on how the language is compiled/interpreted, it can be much slower than pure ASM or straight-up binary if you want to be that "hardcore" (I don't recommend it.). But even though high-level languages are slower than low-level ones, you shouldn't really notice the trade-off with our current computers, which are much faster than the ones when low-level languages were the only thing around.

The "slowness" of high-level languages doesn't just come from converting the code to something the machine understands, but also because just about all those things that you can do on high-level languages can be considered to be made up of a bunch of those "little" ASM instructions, so you don't have to waste time writing a whole loop in ASM in order to multiplicate (even an ASM multiplicate instruction is made up of a bunch of lesser instructions that are more expensive than, say, addition).

So, yeah. Don't knock off high-level languages just because you can understand them. Don't pay attention to "elitists" or whoever that might claim that only real programmers use ASM or C (If anything, real programmers should know ASM and C, but not make them the defacto language to use).

Oh. Use methods when you want to write reusable code. You do this even in C (called functions) and a sorta bizarre variant in ASM (where you sorta... use Jump and Return instructions for them [and labels], but they're not really "call and use" and can screw things up if you're not careful with what you do to registers)

Quote
Hell, I couldn't even read it at a glance now and it was my code! lol

You might want to put better comments and more frequently too. Also, keeping consistency in your indentation and leaving spaces between your routines is a good idea too. It was a little difficult to read and I thought most of it was just a long routine until I took a closer look and noticed a few labels here and there.

Also, my ASM is rusty because I haven't used it since I took my ASM class.

Edit: I just read this and it's completely relevant:
"Premature optimization is the root of all evil."

A programmer should focus on things like profiling code and better algorithms as far as performance goes. Code readability and maintainability should be higher priorities yet, so that you can go back and optimize and fix bugs once you know where the actual problem is. Shaving a few cycles here and there is silly. Only a tiny fraction of your code gets run often enough to warrant any kind of concern over speed. And, on a personal level, if my code is harder to understand and maintain, I'm much less likely to finish or update a project I'm working on.
« Last Edit: December 03, 2012, 11:21:39 am by Garoth Moulinoski »
Who will quote me next?
Disclaimer: If it sounds wrong, I may have been posting while asleep.

relminator

  • Jr. Member
  • **
  • Posts: 27
    • View Profile
Re: Stupid issues with VB.NET
« Reply #17 on: December 03, 2012, 07:47:09 pm »
@Garoth Moulinoski : You might want to know that the source is for a 256-byte demo.  Yes a gfx demo using just 256 bytes so readability is not as important as fitting everything in 256 bytes.

tryphon

  • Hero Member
  • *****
  • Posts: 722
    • View Profile
Re: Stupid issues with VB.NET
« Reply #18 on: December 04, 2012, 05:58:32 am »
Quote
"Premature optimization is the root of all evil."

Glory be to Knuth,
Hallowed be Thy Name

BRPXQZME

  • Hero Member
  • *****
  • Posts: 4572
  • じー
    • View Profile
    • The BRPXQZME Network
Re: Stupid issues with VB.NET
« Reply #19 on: December 04, 2012, 06:36:08 am »
You might want to put better comments and more frequently too. Also, keeping consistency in your indentation and leaving spaces between your routines is a good idea too. It was a little difficult to read and I thought most of it was just a long routine until I took a closer look and noticed a few labels here and there.
Nah, I found it readable enough as long as you’re up to speed on some fairly well known DOS conventions and understand the algorithms involved. Could maybe be more consistent with indentation or whatever.

@Garoth Moulinoski : You might want to know that the source is for a 256-byte demo.  Yes a gfx demo using just 256 bytes so readability is not as important as fitting everything in 256 bytes.
Readability is mostly a concern for maintainability. The constraints of the problem don’t have much to do with that!
we are in a horrible and deadly danger