如何仅使用命令按钮和文本框(vb6)创建循环 [英] How do I make a loop only by using a command button and textbox (vb6)

查看:74
本文介绍了如何仅使用命令按钮和文本框(vb6)创建循环的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

基本上我想要这样做:



当我在文本框中输入5时



然后我按下一个命令按钮,输出应该是:



1

12

123
1234

12345





请出示代码(vb6)

解决方案

我可以为您的问题陈述建议您使用c#代码:





< pre lang =cs> public string ConvertToText( string text)
{
int a;
string output = string .Empty;
if Int32 .TryParse(text, out a))
{
for int i = 1 ; i< = a; i ++)
{
for int j = 1 ; j< = i; j ++)
{
output + = Convert.ToString(J);
}
输出+ = \ n; // 此处您可以使用vb6的特定新行字符替换
}
}
return 输出;
}







和合适的vb代码



 公共 功能 ConvertToText( ByVal  text  As   String 作为 字符串 
Dim a 作为 整数
Dim 输出 As String = string .Empty
如果 Int32 .TryParse(text,a)那么
Dim i 作为 整数 = 1
虽然(i< = a)
Dim j As 整数 = 1
执行 while (j< = i)
output =(output + Convert.ToString(j))
j =(j + 1
循环
输出=(输出+ & vbLf)
' 在这里你可以用vb6的特定新行字符替换
i =(i + 1
循环
结束 如果
返回输出
结束 功能


Basically this want I want to do:

When I enter 5 in a textbox

Then I press a command button the out put should be:

1
12
123
1234
12345


Please show me the code (vb6)

解决方案

i can suggest you c# code for your problem statement :


public string ConvertToText(string text)
        {
            int a;
            string output=string.Empty;
            if(Int32.TryParse(text,out a))
            {
                for(int i=1;i<=a;i++)
                {
                    for(int j=1;j<=i;j++)
                    {
                        output +=Convert.ToString(j);
                    }
                    output+="\n"; // here you can replace with specific new line character of vb6
                }
            }
            return output;
        }




and suitable vb code

Public Function ConvertToText(ByVal text As String) As String
       Dim a As Integer
       Dim output As String = string.Empty
       If Int32.TryParse(text, a) Then
           Dim i As Integer = 1
           Do While (i <= a)
               Dim j As Integer = 1
               Do While (j <= i)
                   output = (output + Convert.ToString(j))
                   j = (j + 1)
               Loop
               output = (output + ""& vbLf)
               ' here you can replace with specific new line character of vb6
               i = (i + 1)
           Loop
       End If
       Return output
   End Function


这篇关于如何仅使用命令按钮和文本框(vb6)创建循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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