Hello can anyone please help me with some code, as you may be aware ASC means:
Function Asc(String As String) As Integer

Public Function Zeichen_OUT(Zeichen As String, wheelNr As Integer) As String
'go left, direction reflector (Umkehrwalze)
Dim Z As Integer
Dim offsetZ As Integer
offsetZ = RotorOffset(wheelNr) - RingOffset(wheelNr)
Z = (Asc(Zeichen) - 64) + offsetZ
If Z < 1 Then Z = Z + 26
If Z > 26 Then Z = Z - 26
Zeichen = Mid(ROTORS(RotorType(wheelNr)), Z, 1)
Z = (Asc(Zeichen) - 64) - offsetZ
If Z < 1 Then Z = Z + 26
If Z > 26 Then Z = Z - 26
Zeichen_OUT = Chr(Z + 64)
End Function

I need some code which will work for string as string as string as integer and so on, as you know asc only works for

Public Function Zeichen_OUT(Zeichen As String, wheelNr As Integer) As String
'go left, direction reflector (Umkehrwalze)
Dim Z As Integer String As String As Integer, is there any where to expand, let say string as string as string as integer, if so can you please amend it and show me please, am designing an machine for maths, I have tried many , none works,

I have tried a as string as string as intefer, but does not work.
Z = (a(Zeichen) - 64) + offsetZ

Nicky


Dim offsetZ As Integer
offsetZ = RotorOffset(wheelNr) - RingOffset(wheelNr)
Z = (Asc(Zeichen) - 64) + offsetZ
If Z < 1 Then Z = Z + 26
If Z > 26 Then Z = Z - 26
Zeichen = Mid(ROTORS(RotorType(wheelNr)), Z, 1)
Z = (Asc(Zeichen) - 64) - offsetZ
If Z < 1 Then Z = Z + 26
If Z > 26 Then Z = Z - 26
Zeichen_OUT = Chr(Z + 64)
End Function

Recommended Answers

All 9 Replies

Hi helloworld,

I really don't understand what you mean when you say
"Dim Z As Integer String As String As Integer"
since this is an illegal syntax in any flavor of VB. A variable can only be declared as one type so this makes no sense.

Could you please tell us what you are trying to do? That way we might be able to find a way to help you.

Thx

Yomet

What I want to do is the same thing as this bellow, but without using the ASC function, is there a way, there must be a way doing it without ACS function, I just don’t know one, can anyone help please

Public Function Zeichen_OUT(Zeichen As String, wheelNr As Integer) As String
'go left, direction reflector (Umkehrwalze)
Dim Z As Integer
Dim offsetZ As Integer
offsetZ = RotorOffset(wheelNr) - RingOffset(wheelNr)
Z = (Asc(Zeichen) - 64) + offsetZ
If Z < 1 Then Z = Z + 26
If Z > 26 Then Z = Z - 26
Zeichen = Mid(ROTORS(RotorType(wheelNr)), Z, 1)
Z = (Asc(Zeichen) - 64) - offsetZ
If Z < 1 Then Z = Z + 26
If Z > 26 Then Z = Z - 26
Zeichen_OUT = Chr(Z + 64)
End Function

Since ASC() returns the ASCII code of a character and the code snippet you present us then subtracts 64 in order to make A=1 instead of 65, you could easily make an array of 26 letters (A-Z) and use the index of the array instead of the ASCII code, i.e. Chars(1) = A, Chars(2) = B, ....

In the code you would loop through the array until you find the letter you have been passed and then use the index for it instead of Asc(Zeichen) - 64.

When the time comes to return the value as in Zeichen_OUT = Chr(Z + 64) you would simply say Zeichen_OUT = Chars(Z).

Hope this helps

Happy coding

Yomet

Hello thank you, this will help me a lot, but am not as good at programming, can you please do that part of the code for me, please.

Public Function Zeichen_OUT(Zeichen As String, wheelNr As Integer) As String
'go left, direction reflector (Umkehrwalze)
Dim Z As Integer
Dim offsetZ As Integer
offsetZ = RotorOffset(wheelNr) - RingOffset(wheelNr)
Z = (Asc(Zeichen) - 64) + offsetZ
If Z < 1 Then Z = Z + 26
If Z > 26 Then Z = Z - 26
Zeichen = Mid(ROTORS(RotorType(wheelNr)), Z, 1)
Z = (Asc(Zeichen) - 64) - offsetZ
If Z < 1 Then Z = Z + 26
If Z > 26 Then Z = Z - 26
Zeichen_OUT = Chr(Z + 64)
End Function

I know am asking for a lot, but it would really help me a lot,if I just know how to do this part I could get on with the rest, am just a beginner, and I need to show my tutor in the next few days, please, I hope you will help me

nicky

i have wrote this but does not work, can you please have a look please
public function MyOwnASC ( aLetter as string) as integer
dim tmp as string
tmp="ABCDEFGHIJKLMNOPQRSTUVWXYZ"
MyOwnASC =instr(1,tmp,aLetter)
end function

Hi helloworld,

Your function should work fine, and it gives the correct results when I test it. So I think your problem is simply how you use it in your code.

Remember that "A" has ASCII value 65 so in your original code the value 64 is subtracted from 65 to make "A" have the final value of 1. In your code "A" already has the value 1 so you cannot subtract 64 from it (it will then have the value of -63). This might be your problem.

What you need to do is to replace Asc(Zeichen) - 64 with MyOwnASC(Zeichen) and then replace Chr(Z + 64) with MyOwnCHR(Z).

public function MyOwnCHR ( aInteger as integer) as string
dim tmp as string
tmp="ABCDEFGHIJKLMNOPQRSTUVWXYZ"
MyOwnCHR =Mid(tmp,aInteger, 1)
end function

Does this correspond to what happened?

Happy coding

Yomet

P.S. No need to send personal messages or e-mails since I receive a notification when you post a reply.

hello yomet, will it be possible for me to send you an attachment with the work i have done, i would like some advice, i would send you it on the forom but can't because other staff may be doing the same work

Helloworld,

Please see my PM to you about this and remember that beside the project being sent to me everything else stays on the forum.

Thanks

Yomet

please check your email

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.