VBForums.com  

VB Wire News



Go Back   VBForums.com > General > Code It Better
User Name
Password
Register FAQ Members List Calendar Today's Posts

Reply Post New Thread
Thread Tools Search this Thread Display Modes
Old 04-12-2005, 12:49 PM   #1
timeshifter
Hyperactive Member

timeshifter's Avatar

Join Date: Mar 04
Location: Smallville, U.S.A. StillVBNoob = True
Posts: 330
timeshifter is on a distinguished road (10+)
Note transposer program may or may not need help...

I've written a little program that just tells you what to replace what chord with what in a song, and I'm not sure it could be made any faster, but I just wanted to make sure before I go about updating it to a much higher standard, so any advice on how to "Code It Better" would be much appreciated.

Thanks!
Attached Files
File Type: frm frmMusic.frm (21.9 KB, 9 views)
__________________


The statement below is false.
The above statement is true.

PM me if you know which one is true!

I can't help anyone, but please Rate my posts good anyway.
timeshifter is offline   Reply With Quote
Old 04-13-2005, 02:27 AM   #2
Maven
Addicted Member

Maven's Avatar

Join Date: Feb 03
Location: Greeneville, TN
Posts: 216
Maven is on a distinguished road (10+)
Re: Note transposer program may or may not need help...

Quote:
Originally Posted by timeshifter
I've written a little program that just tells you what to replace what chord with what in a song, and I'm not sure it could be made any faster, but I just wanted to make sure before I go about updating it to a much higher standard, so any advice on how to "Code It Better" would be much appreciated.

Thanks!


Don't use the following syntax to declaring variables:

Dim diff%
Dim temp%

Instead say Dim myvar as something

You're loops are tiny, you may want to try out unrolling. However I don't know how responsive visual basic will be to that optimization technique.
__________________
Education is an admirable thing, but it is well to remember from time to time that nothing that is worth knowing can be taught.
Maven is offline   Reply With Quote
Old 04-13-2005, 03:07 PM   #3
timeshifter
Hyperactive Member

timeshifter's Avatar

Join Date: Mar 04
Location: Smallville, U.S.A. StillVBNoob = True
Posts: 330
timeshifter is on a distinguished road (10+)
Re: Note transposer program may or may not need help...

What do you mean by unrolling?
__________________


The statement below is false.
The above statement is true.

PM me if you know which one is true!

I can't help anyone, but please Rate my posts good anyway.
timeshifter is offline   Reply With Quote
Old 04-13-2005, 08:41 PM   #4
dglienna
PowerPoster

dglienna's Avatar

Join Date: Jun 04
Location: Center of it all
Posts: 9,605
dglienna is a jewel in the rough (200+)dglienna is a jewel in the rough (200+)dglienna is a jewel in the rough (200+)
Re: Note transposer program may or may not need help...

Quote:
Originally Posted by Maven
Don't use the following syntax to declaring variables:

Dim diff%
Dim temp%

Instead say Dim myvar as something

You're loops are tiny, you may want to try out unrolling. However I don't know how responsive visual basic will be to that optimization technique.



% is shorthand from the old days for a INTEGER type.
I copied this from an old thread.
Quote:
Integer %
Long &
Single !
Double #
Currency @
String $


I would use a table that you could use to look up each one, so that you could just loop through each note, after knowing the amount to transpose in advance.
__________________


David
Don't forget to add the Checkmark and the word [RESOLVED] to the subject of the first post in your thread.
If your question has been answered satisfactorily,
and it has been helpful,
then, please,



Rate this Post!
Information about: Rate this Post.

Last edited by dglienna : 04-13-2005 at 08:46 PM.
dglienna is online now   Reply With Quote
Old 04-14-2005, 01:08 AM   #5
Maven
Addicted Member

Maven's Avatar

Join Date: Feb 03
Location: Greeneville, TN
Posts: 216
Maven is on a distinguished road (10+)
Re: Note transposer program may or may not need help...

Quote:
Originally Posted by dglienna
% is shorthand from the old days for a INTEGER type.
I copied this from an old thread.


I would use a table that you could use to look up each one, so that you could just loop through each note, after knowing the amount to transpose in advance.


I've seen it before but it's not very good pratice to use. I'm also unsure if visual basic converts that at runtime or compile time, if it does it at runtime then it's by default a varient and would effect speed.
__________________
Education is an admirable thing, but it is well to remember from time to time that nothing that is worth knowing can be taught.
Maven is offline   Reply With Quote
Old 04-14-2005, 07:51 AM   #6
RhinoBull
PowerPoster

RhinoBull's Avatar

Join Date: Mar 04
Posts: 4,101
RhinoBull has a spectacular aura about (100+)RhinoBull has a spectacular aura about (100+)
Re: Note transposer program may or may not need help...

Quote:
Originally Posted by Maven
Don't use the following syntax to declaring variables:

Dim diff%
Dim temp%
...

Why the heck not - it's the same thing - just syntax that's different.
Only problem with "shortcuts" is that many new programmers don't know what that symbol stands for but you may use TypeName() function to get actual datatype of any of your variables.
Search through my posts and you will find a sample that demonstrates all of the above - I think I posted it few days ago.

Cheers.
RhinoBull is offline   Reply With Quote
Old 04-14-2005, 11:42 AM   #7
Maven
Addicted Member

Maven's Avatar

Join Date: Feb 03
Location: Greeneville, TN
Posts: 216
Maven is on a distinguished road (10+)
Re: Note transposer program may or may not need help...

Quote:
Originally Posted by RhinoBull
Why the heck not - it's the same thing - just syntax that's different.
Only problem with "shortcuts" is that many new programmers don't know what that symbol stands for but you may use TypeName() function to get actual datatype of any of your variables.
Search through my posts and you will find a sample that demonstrates all of the above - I think I posted it few days ago.

Cheers.


It's a standard coding convetion to use "As Type" clause. I also remember reading something in MSDN that said if you didn't use "As Type" then the variable would be defined a varient. I'm thinking visual basic may convert this at compile time since there is some type of identification but even so, I think it's horrible coding style.
__________________
Education is an admirable thing, but it is well to remember from time to time that nothing that is worth knowing can be taught.

Last edited by Maven : 04-14-2005 at 11:49 AM.
Maven is offline   Reply With Quote
Old 04-14-2005, 04:39 PM   #8
RhinoBull
PowerPoster

RhinoBull's Avatar

Join Date: Mar 04
Posts: 4,101
RhinoBull has a spectacular aura about (100+)RhinoBull has a spectacular aura about (100+)
Re: Note transposer program may or may not need help...

You are totally confused :

declaring variable without the type specified will result in Variant type - that is true.
However,
declaring variable as

Dim intNumber%
or
Dim intNumber As Integer

WILL result in both case and INTEGER variable immediately.

Also, if you would look closely at how windows api work then you will find in many many samples that some arguments are passed with ampersand at the end:

Call SomeFunction(arg1&, arg2&)

that is done on purpose to explicitly convert integer to long and therefore

declaring variable as ...
Dim lngNumber&

is perfectly valid and normal way of declaring variables.

The only problem (as I said before) not using "...As SomeType" syntax is that majority of new programmers wouldn't know what that symbol is.
But there are so many things not documented, though ...

And after all what is "standard coding convetion anyway ?..

Best regards.
RhinoBull is offline   Reply With Quote
Old 04-15-2005, 01:36 AM   #9
Maven
Addicted Member

Maven's Avatar

Join Date: Feb 03
Location: Greeneville, TN
Posts: 216
Maven is on a distinguished road (10+)
Re: Note transposer program may or may not need help...

Quote:
Originally Posted by RhinoBull
You are totally confused :

declaring variable without the type specified will result in Variant type - that is true.
However,
declaring variable as

Dim intNumber%
or
Dim intNumber As Integer

WILL result in both case and INTEGER variable immediately.

Also, if you would look closely at how windows api work then you will find in many many samples that some arguments are passed with ampersand at the end:

Call SomeFunction(arg1&, arg2&)

that is done on purpose to explicitly convert integer to long and therefore

declaring variable as ...
Dim lngNumber&

is perfectly valid and normal way of declaring variables.

The only problem (as I said before) not using "...As SomeType" syntax is that majority of new programmers wouldn't know what that symbol is.
But there are so many things not documented, though ...

And after all what is "standard coding convetion anyway ?..

Best regards.


Microsoft Def:

Quote:
Coding conventions are programming guidelines that focus not on the logic of the program but on its physical structure and appearance. They make the code easier to read, understand, and maintain.


To give you an example, I'm going to use the GOTO statement. It's something that you can use if you wanted to in visual basic. You could after all create a loop or even a if structure out of goto statements. However, it kills the idea of structured programming. I use GOTO as an example because it's probably the most extreme keyword supported by visual basic.

Another reason to stay mainstream is the possibility that it will be more likely to be droped if it's outside of the standard way of doing things. If that happens then all of you're code will break if you try to port it.
__________________
Education is an admirable thing, but it is well to remember from time to time that nothing that is worth knowing can be taught.
Maven is offline   Reply With Quote
Old 04-15-2005, 08:32 PM   #10
RhinoBull
PowerPoster

RhinoBull's Avatar

Join Date: Mar 04
Posts: 4,101
RhinoBull has a spectacular aura about (100+)RhinoBull has a spectacular aura about (100+)
Re: Note transposer program may or may not need help...

Let me guess: you're a student, you do programming for about 2-3 years at most but you sound like professor reading directly from one of the academic book ...
Just wonder where do you get these ideas from ??? Really silly ...
RhinoBull is offline   Reply With Quote
Old 04-16-2005, 12:19 AM   #11
Maven
Addicted Member

Maven's Avatar

Join Date: Feb 03
Location: Greeneville, TN
Posts: 216
Maven is on a distinguished road (10+)
Re: Note transposer program may or may not need help...

Quote:
Originally Posted by RhinoBull
Let me guess: you're a student, you do programming for about 2-3 years at most but you sound like professor reading directly from one of the academic book ...
Just wonder where do you get these ideas from ??? Really silly ...


I think any sensible programmer would agree that it's very important to follow the standard guidelines of programming. You may not understand why these guidelines are important if you're writing very simple programs but as a program increases in size and complexity, it becomes very obvious as to why those standards exist.
__________________
Education is an admirable thing, but it is well to remember from time to time that nothing that is worth knowing can be taught.
Maven is offline   Reply With Quote
Old 04-19-2005, 09:17 PM   #12
RhinoBull
PowerPoster

RhinoBull's Avatar

Join Date: Mar 04
Posts: 4,101
RhinoBull has a spectacular aura about (100+)RhinoBull has a spectacular aura about (100+)
Re: Note transposer program may or may not need help...

Yea, that's what I thought.
RhinoBull is offline   Reply With Quote
Old 05-01-2005, 08:45 PM   #13
Sastraxi
Good Ol' Platypus

Sastraxi's Avatar

Join Date: Jan 00
Location: Ontario, Canada
Posts: 5,154
Sastraxi is on a distinguished road (10+)
Re: Note transposer program may or may not need help...

I think it's standard for any sensible programmer to use a sensible language.
Yipes.
They might also stay on topic.
__________________
All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
(Just a heads-up)
Sastraxi is offline   Reply With Quote
Old 05-03-2005, 11:59 PM   #14
Dreamlax
Hyperactive Member

Join Date: Jul 02
Location: WGTN, New Zealand
Posts: 322
Dreamlax is on a distinguished road (10+)
Re: Note transposer program may or may not need help...

Apparently whenever you using string manipulation functions, such as Left and Mid, you should always use Left$() or Mid$() because otherwise it returns a variant and converts it back to a string. Veeery useless.
Dreamlax is offline   Reply With Quote
 
Reply Post New Thread



Go Back   VBForums.com > General > Code It Better

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump




All times are GMT -5. The time now is 01:48 PM.

Acceptable Use Policy

JupiterWeb networks:

internet.comearthweb.comDevx.comClickZGraphics.com

Search JupiterWeb:

Jupitermedia Corporation has four divisions:
JupiterWeb, JupiterResearch, JupiterEvents and JupiterImages

Copyright 2005 Jupitermedia Corporation All Rights Reserved.
Legal Notices, Licensing, Reprints, & Permissions, Privacy Policy.

Jupitermedia Corporate Info | Newsletters | Tech Jobs | E-mail Offers


Powered by: vBulletin Version 3.0.3
Copyright ©2000 - 2005, Jelsoft Enterprises Ltd.
Copyright Jupitermedia Corp. 2002-2005