|
-
Apr 12th, 2005, 12:49 PM
#1
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!
-
Apr 13th, 2005, 02:27 AM
#2
Hyperactive Member
Re: Note transposer program may or may not need help...
 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. - Oscar Wilde
-
Apr 13th, 2005, 03:07 PM
#3
Re: Note transposer program may or may not need help...
What do you mean by unrolling?
-
Apr 13th, 2005, 08:41 PM
#4
Re: Note transposer program may or may not need help...
 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.
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.
Last edited by dglienna; Apr 13th, 2005 at 08:46 PM.
-
Apr 14th, 2005, 01:08 AM
#5
Hyperactive Member
Re: Note transposer program may or may not need help...
 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. - Oscar Wilde
-
Apr 14th, 2005, 07:51 AM
#6
Re: Note transposer program may or may not need help...
 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.
-
Apr 14th, 2005, 11:42 AM
#7
Hyperactive Member
Re: Note transposer program may or may not need help...
 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.
Last edited by Maven; Apr 14th, 2005 at 11:49 AM.
Education is an admirable thing, but it is well to remember from time to time that nothing that is worth knowing can be taught. - Oscar Wilde
-
Apr 14th, 2005, 04:39 PM
#8
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.
-
Apr 15th, 2005, 01:36 AM
#9
Hyperactive Member
Re: Note transposer program may or may not need help...
 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:
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. - Oscar Wilde
-
Apr 15th, 2005, 08:32 PM
#10
-
Apr 16th, 2005, 12:19 AM
#11
Hyperactive Member
Re: Note transposer program may or may not need help...
 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. - Oscar Wilde
-
Apr 19th, 2005, 09:17 PM
#12
Re: Note transposer program may or may not need help...
Yea, that's what I thought.
-
May 1st, 2005, 08:45 PM
#13
Good Ol' Platypus
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)
-
May 3rd, 2005, 11:59 PM
#14
Hyperactive Member
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.
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
|