将VB代码转换为C代码。 [英] Convert VB code to C code.

查看:135
本文介绍了将VB代码转换为C代码。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




我无法将以下几行Visual Basic

代码翻译成C.


for iCounter = Len(sReference)To 1 Step -1

iSum = iSum + Val(Mid(sReference,iCounter,1))* iMultiplier

Next


fReferenceCheckSum =右(Str(10 - (iSum Mod 10)),1)


任何人的想法?我有一些帮助,但我需要知道C'的FOR

循环是什么样的,以及'Val(Mid .."和'Right(Str ...") ;

翻译成C.任何进一步的帮助将不胜感激。


谢谢,

Kenneth

Hi,

I am having trouble translating the following lines of Visual Basic
code to C.

For iCounter = Len(sReference) To 1 Step -1
iSum = iSum + Val(Mid(sReference, iCounter, 1)) * iMultiplier
Next

fReferenceCheckSum = Right(Str(10 - (iSum Mod 10)), 1)

Any ideas anyone? I have had some help, but I need to know how C''s FOR
loops looks like, and how "Val(Mid.." and "Right(Str..." are
translated into C. Any further help would be greatly appreciated.

Thanks,
Kenneth

推荐答案

嗯。有趣的,但奇怪的是不合适,在这个上面的交叉点列表

这个。


在文章< ce ************************** @ posting.google.com> ;,

Kenneth Osenbroch< ke *************** @ telenor.com>写道:
Hmm. Interesting, yet oddly not inappropriate, crosspost list on
this one.

In article <ce**************************@posting.google.com >,
Kenneth Osenbroch <ke***************@telenor.com> wrote:


我无法翻译以下几行Visual Basic
代码到C.

对于iCounter = Len(sReference)到1步-1
iSum = iSum + Val(Mid(sReference,iCounter,1 ))* iMultiplier
下一页

fReferenceCheckSum =右(Str(10 - (iSum Mod 10)),1)

任何人的想法?我有一些想法帮助,但我需要知道如何C'的FOR
循环看起来像,


你会想要得到一本教科书(或者知道C的人)。

获得语言的基本知识,然后*然后*开始将代码

翻译成它。


小心选择教科书,因为有很多坏的那个

那里。其中一个最好的,特别是如果你已经用其他语言做了一些编程

,那就是_The C Programming Language,2nd edition_ by

Kernighan和Ritchie。


以及如何Val(Mid .."和Right(Str ...被翻译成C。
Hi,

I am having trouble translating the following lines of Visual Basic
code to C.

For iCounter = Len(sReference) To 1 Step -1
iSum = iSum + Val(Mid(sReference, iCounter, 1)) * iMultiplier
Next

fReferenceCheckSum = Right(Str(10 - (iSum Mod 10)), 1)

Any ideas anyone? I have had some help, but I need to know how C''s FOR
loops looks like,
You''ll want to get a textbook (or somebody who knows C) for this.
Get a basic knowledge of the language, and *then* start translating code
into it.

Be careful choosing textbooks, because there are a lot of bad ones
out there. One of the best, especially if you''ve done some programming
in other languages, is _The C Programming Language, 2nd edition_ by
Kernighan and Ritchie.

and how "Val(Mid.." and "Right(Str..." are
translated into C.




如果我正确地记住了Commodore 64的错误青年,

并且如果VB继承它们(来自那里或来自共同来源)没有

太多的变化(或者如果我的错误记忆和VB的拥抱和扩展已经以类似的方式修改了它们),Val将字符串转换为数字值

和Right取字符串的最后N个字符。(此处的代码片段

也使用Mid,它从字符串中间取出一个子字符串。)


如果这是不正确的,我相信我们会在VB新闻组中听到某人的消息




查找sscanf for conv将字符串转换为数字值。


C中的字符串只是字符数组,因此您可以通过将适当的字符集复制到另一个字符串来处理子字符串

操作

缓冲并适当地终止它。小心什么是

where;你需要自己做所有的记忆管理,这会让人感觉很好,因为他们来自Basic-ish背景,具有很强的可预测性。

dave


-

Dave Vandervies dj ****** @ csclub.uwaterloo.ca

他应该做的事与我上周的做法类似。当它空了的时候我闯入了他家的房子里,并且错误地把卫生间转了一圈。

- 在comp.lang.c中跟Godfrey一起



If I''m remembering my misspent youth with the Commodore 64 correctly,
and if VB has inherited them (from there or from a common source) without
too many changes (or if my misremembering and VB''s embrace-and-extend have
modified them in similar ways), Val converts a string into a numeric value
and Right takes the last N characters of a string. (The code snippet here
also uses Mid, which takes a substring out of the middle of a string.)

If that''s incorrect, I''m sure we''ll be hearing about it from somebody
in the VB newsgroup.

Look up sscanf for converting strings into numeric values.

Strings in C are just arrays of characters, so you can handle substring
operations by copying the appropriate set of characters into another
buffer and terminating it appropriately. Be careful with what goes
where; you need to do all the memory management yourself, which bites
people coming from Basic-ish backgrounds with great predictability.
dave

--
Dave Vandervies dj******@csclub.uwaterloo.ca
He should have done something similar to what I did last week. I broke into
his house when it was empty and turned the toilet roll around the wrong way.
--Bill Godfrey in comp.lang.c


Kenneth Osenbroch写道:
Kenneth Osenbroch wrote:

我无法将以下几行Visual Basic代码转换为C.

对于iCounter = Len(sReference)到1步-1
iSum = iSum + Val(Mid(sReference,iCounter,1))* iMultiplier
下一页

fReferenceCheckSum =对(Str(10 - (iSum Mod 10)),1)

任何人的想法?我有一些帮助,但我需要知道C'的FOR循环是什么样的,以及'Val(Mid .."和'Right(Str ...)是怎样的?非常感谢任何进一步的帮助。

I am having trouble translating the following lines of Visual Basic
code to C.

For iCounter = Len(sReference) To 1 Step -1
iSum = iSum + Val(Mid(sReference, iCounter, 1)) * iMultiplier
Next

fReferenceCheckSum = Right(Str(10 - (iSum Mod 10)), 1)

Any ideas anyone? I have had some help, but I need to know how C''s
FOR loops looks like, and how "Val(Mid.." and "Right(Str..." are
translated into C. Any further help would be greatly appreciated.




这里的clc我们不知道那些函数是做什么的。但是我

可以给你一个等价的for语句:


for(iCounter = Len(...); / *初始化* /

iCounter > = 1; / *继续条件* /

iCounter--)/ *循环更改操作* /

{

/ *无论如何这个有趣的说法确实* /

}


但却失去了丑陋的匈牙利符号。


-

Chuck F(cb********@yahoo.com)(cb********@worldnet.att.net)

可用于咨询/临时嵌入式和系统。

< http://cbfalconer.home.att.net>使用worldnet地址!



Here in c.l.c we have no idea what those functions do. However I
can give you a C equivalent of the for statement:

for (iCounter = Len(...); /* initialization */
iCounter >= 1; /* continue condition */
iCounter--) /* loop alteration action */
{
/* whatever that funny statement does */
}

but lose the ugly hungarian notation.

--
Chuck F (cb********@yahoo.com) (cb********@worldnet.att.net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net> USE worldnet address!




Kenneth Osenbroch <柯*************** @ telenor.com>在消息中写道

news:ce ************************** @ posting.google.c om ...

"Kenneth Osenbroch" <ke***************@telenor.com> wrote in message
news:ce**************************@posting.google.c om...


我无法将以下几行Visual Basic
代码转换为C.

对于iCounter = Len( sReference)到1步-1
iSum = iSum + Val(Mid(sReference,iCounter,1))* iMultiplier
下一页

fReferenceCheckSum = Right(Str(10 - ( iSum Mod 10)),1)

任何想法?我有一些帮助,但我需要知道C'的FOR
循环是什么样的,以及Val(Mid ...和Right(Str ...)是怎样的非常感谢任何进一步的帮助。
Hi,

I am having trouble translating the following lines of Visual Basic
code to C.

For iCounter = Len(sReference) To 1 Step -1
iSum = iSum + Val(Mid(sReference, iCounter, 1)) * iMultiplier
Next

fReferenceCheckSum = Right(Str(10 - (iSum Mod 10)), 1)

Any ideas anyone? I have had some help, but I need to know how C''s FOR
loops looks like, and how "Val(Mid.." and "Right(Str..." are
translated into C. Any further help would be greatly appreciated.




我想(请注意你的c'数组基于0,我不是知道vb):

for(iCounter = strlen(sReference); iCounter> 0; iCounter--)

iSum + = atoi(sReference [i-1])* iMultiplier ;


// buf在这里作为字符串缓冲区添加

sprintf(buf,"%d",10-(iSum%10));

fReferenceChecksum = atoi(buf [strlen(buf)-1]);


这只是一个猜测(我认为最后一个会受到影响)来自

类型的错误,但是afaik vb也可以插入隐式强制)。



I think (mind you c''s arrays are 0 based, and I don''t know vb):
for(iCounter=strlen(sReference); iCounter>0; iCounter--)
iSum+=atoi(sReference[i-1])*iMultiplier;

//buf is added here as a string buffer
sprintf(buf, "%d", 10-(iSum%10));
fReferenceChecksum=atoi(buf[strlen(buf)-1]);

this is just a guess (I would think the last one would have suffered from a
type error, but afaik vb can also insert implicit coercions).


这篇关于将VB代码转换为C代码。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆