Register | Login | |||||
Main
| Memberlist
| Active users
| Calendar
| Chat
| Online users Ranks | FAQ | ACS | Stats | Color Chart | Search | Photo album |
| |
0 users currently in Programming. |
Acmlm's Board - I3 Archive - Programming - ok i need some help with VB6 | New poll | | |
Add to favorites | Next newer thread | Next older thread |
User | Post | ||
Crayola Double stone axe Since: 03-18-06 From: coeburn,VA Last post: 6366 days Last view: 6329 days |
| ||
heres my code so far :
Private Sub cmd1_Click() If decimal = "0" Then ascii = "NUL" If hex = "0" Then ascii = "NUL" If octal = "000" Then ascii = "NUL" If decimal = "1" Then ascii = "SOH" If hex = "1" Then ascii = "SOH" If octal = "001" Then ascii = "SOH" If decimal = "2" Then ascii = "STX" If hex = "2" Then ascii = "STX" If octal = "002" Then ascii = "STX" If decimal = "3" Then ascii = "ETX" If hex = "3" Then ascii = "ETX" If octal = "003" Then ascii = "ETX" If decimal = "4" Then ascii = "EOT" If hex = "4" Then ascii = "EOT" If octal = "004" Then ascii = "EOT" If decimal = "5" Then ascii = "ENQ" If hex = "5" Then ascii = "ENQ" If octal = "005" Then ascii = "ENQ" If decimal = "6" Then ascii = "ACK" If hex = "6" Then ascii = "ACK" If octal = "006" Then ascii = "ACK" If decimal = "7" Then ascii = "BEL" If hex = "7" Then ascii = "BEL" If octal = "007" Then ascii = "BEL" If decimal = "8" Then ascii = "BS" If hex = "8" Then ascii = "BS" If octal = "010" Then ascii = "BS" If decimal = "9" Then ascii = "TAB" If hex = "9" Then ascii = "TAB" If octal = "011" Then ascii = "TAB" If decimal = "10" Then ascii = "LF" If hex = "A" Then ascii = "LF" If octal = "012" Then ascii = "LF" If decimal = "11" Then ascii = "VT" If hex = "B" Then ascii = "VT" If octal = "013" Then ascii = "VT" If decimal = "12" Then ascii = "FF" If hex = "C" Then ascii = "FF" If octal = "014" Then ascii = "FF" If decimal = "13" Then ascii = "CR" If hex = "D" Then ascii = "CR" If octal = "015" Then ascii = "CR" If decimal = "14" Then ascii = "SO" If hex = "E" Then ascii = "SO" If octal = "016" Then ascii = "SO" If decimal = "15" Then ascii = "SI" If hex = "F" Then ascii = "SI" If octal = "017" Then ascii = "SI" If decimal = "16" Then ascii = "DLE" If hex = "10" Then ascii = "DLE" If octal = "020" Then ascii = "DLE" If decimal = "17" Then ascii = "DC1" If hex = "11" Then ascii = "DC1" If octal = "021" Then ascii = "DC1" End Sub im trying to make a converter that converts between hex/ascii/octal/decimal/binary but i have a big problem right now.if i type in lets say 003 in the octal box it will show up in the ascii box as "ETX" and if i type in 004 it will show up as "EOT" how do i get my program to show "ETX?"when i type in 003004 without having to put If octal = "003004" Then ascii = "EXT EOT" if anyone has any idea how to help pleese post cause im lost i just started using vb yesterday so im like a major noob and am just tying this program as practice. the way my converter is so far is that it only does one conversion at a time instead of showing EXT EOT if i want the ascii form of 003004 i have to put in 003 convert it then convert 004 , i want to be able to put 003004 and to get them both converted to their ascii values EXT and EOT at the same time in the same box,im sorry i cant explain myself better. it took a while but i figured out a way to do this (all by myself). anyways Ill need to finish the code then copy and paste five or 6 of the same thing into the code and ill need to change the labels by adding a number to it example HEX1 so the code will now read HEX="HEX1"+HEX2+HEX3+HEX4 and so on theres probably a beter way to do this but i know this way will work.yay!!! (edited by Crayola on 04-10-06 09:44 PM) (edited by Crayola on 04-10-06 10:07 PM) (edited by Crayola on 04-10-06 10:10 PM) (edited by Crayola on 04-11-06 12:57 AM) |
|||
Disch Red Cheep-cheep Since: 12-10-05 Last post: 6578 days Last view: 6578 days |
| ||
For the love of GOD use a lookup table!
rather than a huge freaking if/else chain like you have (which is a horrible wretch to code, maintain, as well as for the computer to execute), just make a constant array with all the strings in it, and then use the number to index it. I don't know any VB, but some C pseudo-code might give you the idea:
where 'number' is 'decimal', 'hex', or 'octal' converted from string form to integer form. |
|||
Crayola Double stone axe Since: 03-18-06 From: coeburn,VA Last post: 6366 days Last view: 6329 days |
| ||
i dont need a " lookup table "i know the conversions in my head but i want to put them in the program i have given up on my first aproach it would take to long and the chance for error on my part would be high.
i really dont understand how to write what you wrote in VB so i need a different code. if decimal=0 then hex=0 ascii=NUL and ocatl=000 the problem is when i put in lets say decimal is 00 what it should say is hex=00 ascii=NULNUL and octal=000000 but it wont show this without me codeing if decimal=00 then hex=00 ascii=NULNUL and octal=000000 the problem is i do not want to code like ive been doing all the way to the "second" it would take forever plus it would take up much more space then nessecary,but i know there is a way to fix it.ive already coded for the basic conversions i just need to know how to fix it. so my question is,how do i get the conversions to be added together to show hex=00 ascii=NULNUL and ocatl=000000 if i put in 00 in the decimal bar,if i already have the basic conversions coded (by basic i mean the values exp (edited by Crayola on 04-11-06 08:15 PM) |
|||
Disch Red Cheep-cheep Since: 12-10-05 Last post: 6578 days Last view: 6578 days |
| ||
Originally posted by Crayola No no.. you misunderstand. The lookup table isn't to help you remember.... A 'lookup table' is a programming concept where you use an array which holds information that you "look up". Instead of saying "if value is this, then use this" a billion times, you simply "look up" the value from a big table. No 'if' statements required. This saves the anguish, tediousness, boredom, and inefficiency of making a gigantic if/else chain. If you don't understand how arrays work or how to impliment them, that's definatly something you should focus on in the near (or immediate) future. As for your other problem, it's hard to address since I don't really understand what you're trying to do. But from what it sounds like, you could just take out the first 3 characters of 'octal' and convert that to ascii, then take the next 3 characters and convert/append them. But that's really as detailed as I can get. My VB knowledge is nill. (edited by Disch on 04-11-06 08:39 PM) |
|||
Crayola Double stone axe Since: 03-18-06 From: coeburn,VA Last post: 6366 days Last view: 6329 days |
| ||
ok i figure out how to make an array ,but what i need is to know how to use them,
lmy array looks sorta like this, Dim X(127, 6) As String Private Sub convert_Click() X(1,1) = "00" 'hex amounts end in 1 ex (0,1) X(1,2) = "NUL" 'ascii amounts end in 2 ex.(0,2) X(1,3) = "0" 'decimal amounts end in 3 ex (0,3) X(1,4) = "000" 'octal amounts end in 4 ex (0,4) X(1,5) = "00000000" 'binary amounts end in 5 ex. (0,5) X(1,6) = "" 'saving this for something hex= X(1,1)-X(127,1) ascii = X(1,2)-X(127,2) [decimal] = X(1,3)-X(127,3) octal = X(1,4)-X(127,4) binary = X(1,5)-X(127,5) ok i made an array or at least part of one (i think) but how do i use it to help me convert the different formats?keeping in mind that i need to convert up to greater integers,ok that didnt work .......i have no idea how to wright what i want i could code it all in "if = then = " but thats not the right/best way so ill keep looking for an answer in the meantime post any valuable data here . (edited by Crayola on 04-12-06 11:08 PM) |
|||
Mega-Dog Since: 11-19-05 From: Minnesota Last post: 6320 days Last view: 6302 days |
| ||
Gesh instad of If's use a case statement...much cleaner code...
Also Ascii, Hex and I also think Oct are reserved VB codes. Be sure to put "Option Explicit" on the top to not duplicate errors and such. I gota fly to work...will come up with a solution there to this VB problem. |
|||
Disch Red Cheep-cheep Since: 12-10-05 Last post: 6578 days Last view: 6578 days |
| ||
Originally posted by Mega-Dog No no no... lookup table > * in this case. The numbers seem to sequential and one number = one string. Just have a fixed array of strings and pull the desired string by index. Much cleaner to code, faster to execute, and easier to edit/maintain. Conditionals (if/else, switch/case) shouldn't be applied here. |
|||
dormento Red Goomba Since: 11-18-05 Last post: 6451 days Last view: 6298 days |
| ||
No no no...
lookup table > * in this case. The numbers seem to sequential and one number = one string. Just have a fixed array of strings and pull the desired string by index. Much cleaner to code, faster to execute, and easier to edit/maintain. Conditionals (if/else, switch/case) shouldn't be applied here. I faintly remember once reading an article about the guts of the VB 'compiler'... iirc it said that Case statements were optimized to simple lookup tables in the eventuality of having only integer constants. I can't remember if it needed to be sequential integer constants though... edit: Can't find the damn article for the life of me... It was on VBExplorer, i think... (edited by dormento on 04-15-06 12:42 AM) |
|||
Disch Red Cheep-cheep Since: 12-10-05 Last post: 6578 days Last view: 6578 days |
| ||
I'm sure they get compiled to a jump table, yeah. But you'll still have different assignment code for each condition.
For some pseudo-code to give the idea: more or less how a switch/case setup will be compiled: goto label_table[ index ]
vs how a string lookup table will be compiled: ascii = string_table[ index ] The former will have a lot of redundent code, and I highly doubt any compiler would be smart enough to merge and optimize the contents of each case label into a simple lookup table like the latter. They both use a lookup table, but the former uses it to jump around instead of just using it to set what it needs to. And plus -- a lookup table is easier to code than a big switch/case block, and much easier to edit/maintain. |
|||
wboy Since: 01-05-06 Last post: 6482 days Last view: 6482 days |
| ||
Originally posted by 1136 Take a look at the following: http://www.pscode.com/vb/scripts/ShowCode.asp?txtCodeId=41809&lngWId=1 Its uses a generic base converter function which handles everything you are after except ascii, though you should be able to add with relative ease and modify the form to your needs. |
Add to favorites | Next newer thread | Next older thread |
Acmlm's Board - I3 Archive - Programming - ok i need some help with VB6 | | |