Thursday 15 August 2013

vb6 - What's wrong with my program? About the Ascii 13[Enter] -


Our last time was an activity that was changing my classmate's Python code to vb ... this is my last code And it's going on.

  Private subtxtInput_KeyPress (key as integer) KeyAscii = 13 then curyear = Int (2013) one = int (curyear - txtInput.Text) Mod 12) txtInput.Text = " "If (a = 9) or (a = -3) then txtOutput.Text =" Your zodiac sign is "Elsef (A = 8) or (a = -4) then txtOutput.Text =" Dragon on your zodiac sign Is Elsef (a = 7) or (a = -5) then txtOutput.Text = "ElseIf (a = 6) or (a = -6) then txtOutput.Text =" your zodiac sign But Tiger is "Elsef (A = 5) or (a = -7) then txtOutput.Text =" Your zodiac sign is "ElseIf (a = 4) or (a = -8) TxtOutput.Text = ElseIf (a = 2) or (a = -10) or (a = -9) then txtOutput.Text = "dash on your zodiac sign" ElseIf (a = 2) or (a = -10) ) Then txtOutput.Text = "ElseIf (a = 1) or (a = -11) then txtOutput.Text =" Your zodiac sign is a sign "ElseIf (a = 0) or (A = - 2) Then txtOutput.Text = "Monkey on your zodiac sign" is Elsef (A = 11) or (A = -1) then txtOutput.Text = "Your zodiac sign is signed" ALAIF (A = 12) or (A = 0) Then txtOutput.Text = "sign your horoscope horse" end if end a And End Sub   

told our professor has other uses I ASCII 13 / ... I could not understand it well. Do you think that my code is wrong? It's running but he said that my code is wrong.

First of all, to clean your code

  • If instead of using all the other statements, then use a better way to choose the case.
  • You do not have Int () on the third or fourth row. It's already an integer.
  • You do not have to repeat the string of "You sign the zodiac sign".
  • And as Dina said, you need to remove ASCII 13 from your textbox input.

    Then, the new code:

      Personal subtxtInput_KeyPress (Keyage as integer) string as Dim ZodiacAnimal if KeyAscii = 13 then curyear = 2013 A = (curyear - txtInput.Text) Mod 12 Select Case Case 9, -3 ZodiacAnimal = "Snake" Case 8, -4 Amount of Anil = "Dragon" Episode 7, -5 Radial Anil = "Rabbit" Case 6, -6 Rashtimak Anil = "Tiger" Case 5, -7 amendment Anil = "Oaks" Case 4, -8 Economic fundamental = "Rat" case 3, -9 Amount of fiscal = "pig" episode 2, -10 ammunition Anil = "dog" Case 1, -1 1 Rashtimak Anil = "Chicken" Case 0, -2 The Economic Anil = "Monkey" Case 11, -1 Zodiac Animate = "Sheep" Case 12, 0 Zodiac Animal = "Horse" and select txtInput.Text = "Your zodiac sign "& Amp;   

    Now, there are some other problems I see.

    • You have a hard coded year. The zodiac is about the year you were born, and there is nothing with the current year.
    • You've listed twice.

      Now, it can be very advanced for you, but here's how I coded it:

        private subtxtInput_KeyPress ( KeyAscii = 13 then ZodiacAnimal = Split ("Monkey, cock, bull, dog, pig, rat, bull, tiger, rabbit, dragon, snake, horse, goat", " , ") TxtInput.Text =" Your zodiac sign "& amp; Zodiac Anemil (Y-Mod 12) K end the end of KASCI with the end sub   

      This creates an array of zodiacal animals, then using the mod function, I get the correct indicator of the array.

No comments:

Post a Comment