Help with Simple Code - VB.net
2014-04-13, 12:35 AM, (This post was last modified: 2014-04-13, 12:43 AM by Scaling.)
#1
Hello guys,

I Have Label1 and Button1.
When i click on button1 label1 change to random number.

I want in each click on button1 the program will save the random number from label1 to the same .txt file. i mean i'll get somethings like this:

.txt file:
Random1
Random2
Random3
....

Help me coing it please in VB.net Thank's!
Reply
2014-04-14, 03:42 AM,
#2
Here's how to do it (you can modify the values to match your needs)
Add this code to the button you want:
Code:
Dim Gen As System.Random
        Gen = New System.Random(My.Computer.Clock.TickCount)
        Dim lbtext As Integer = Gen.Next(1, 100)
        System.IO.File.AppendAllText(Environment.CurrentDirectory + "\textfile.txt", lbtext.ToString + vbNewLine)
        Label1.Text = lbtext
If textfile.txt doesn't exist, it's created automatically.

Result after pressing the button 5 times:
[Image: lCpWO7J.png]

"The master has failed more times than the beginner has even tried"

My VIP Shares:
How to stop Chrome from blocking PPI installers
How to make advanced, custom messageboxes that match your theme in VB.

PM ME FOR A 99% OFF DISCOUNT ON HOSTWINDS
Reply
2014-04-14, 07:27 AM,
#3
(2014-04-14, 03:42 AM)SEO Wrote: Here's how to do it (you can modify the values to match your needs)
Add this code to the button you want:
Code:
Dim Gen As System.Random
        Gen = New System.Random(My.Computer.Clock.TickCount)
        Dim lbtext As Integer = Gen.Next(1, 100)
        System.IO.File.AppendAllText(Environment.CurrentDirectory + "\textfile.txt", lbtext.ToString + vbNewLine)
        Label1.Text = lbtext
If textfile.txt doesn't exist, it's created automatically.

Result after pressing the button 5 times:
[img]/lCpWO7J.png[/img]

Thank's for help but the only problem is i am not need random between 1 to 100, i need date and i am using this code:

PHP Code:
Dim Date1 As DateDate2 As Date
        Date1 
"01/1/1990"
        
Date2 "01/1/1999"

        'number of days between dates
        Dim iDiff = DateDiff("d", Date1, Date2, vbMonday)

        Dim RndDate As Date
        Randomize()
        RndDate = DateAdd("d", Int((iDiff * Rnd()) + 1), Date1)

        FlatTextBox1.Text = RndDate
        Clipboard.SetText(Me.FlatTextBox1.Text, TextDataFormat.Text) 

i just tried to add ur code but it's makes problem with lbtext maybe you can help me pls :)
Reply
2014-04-14, 09:57 AM,
#4
lbtext = labeltext

He doesn't know the exact name of your variable, so he used a general one.
Reply
2014-04-14, 06:35 PM,
#5
(2014-04-14, 07:27 AM)iElite Wrote:
(2014-04-14, 03:42 AM)SEO Wrote: Here's how to do it (you can modify the values to match your needs)
Add this code to the button you want:
Code:
Dim Gen As System.Random
        Gen = New System.Random(My.Computer.Clock.TickCount)
        Dim lbtext As Integer = Gen.Next(1, 100)
        System.IO.File.AppendAllText(Environment.CurrentDirectory + "\textfile.txt", lbtext.ToString + vbNewLine)
        Label1.Text = lbtext
If textfile.txt doesn't exist, it's created automatically.

Result after pressing the button 5 times:
[img]/lCpWO7J.png[/img]

Thank's for help but the only problem is i am not need random between 1 to 100, i need date and i am using this code:

PHP Code:
Dim Date1 As DateDate2 As Date
        Date1 
"01/1/1990"
        
Date2 "01/1/1999"

        'number of days between dates
        Dim iDiff = DateDiff("d", Date1, Date2, vbMonday)

        Dim RndDate As Date
        Randomize()
        RndDate = DateAdd("d", Int((iDiff * Rnd()) + 1), Date1)

        FlatTextBox1.Text = RndDate
        Clipboard.SetText(Me.FlatTextBox1.Text, TextDataFormat.Text) 

i just tried to add ur code but it's makes problem with lbtext maybe you can help me pls :)

(2014-04-14, 09:57 AM)-qwerty- Wrote: lbtext = labeltext

He doesn't know the exact name of your variable, so he used a general one.

i tried this one but it's not working for me, maybe you can fix it pls?

PHP Code:
Dim Date1 As DateDate2 As Date
        Date1 
"01/1/1990"
        
Date2 "01/1/1999"

        'number of days between dates
        Dim iDiff = DateDiff("d", Date1, Date2, vbMonday)

        Dim RndDate As Date
        Randomize()
        RndDate = DateAdd("d", Int((iDiff * Rnd()) + 1), Date1)

        FlatTextBox1.Text = RndDate
        Clipboard.SetText(Me.FlatTextBox1.Text, TextDataFormat.Text)
        System.IO.File.AppendAllText(Environment.CurrentDirectory + "\textfile.txt", FlatLabel1.Text.ToString + vbNewLine)
        FlatLabel1.Text = FlatLabel1.Text 
Reply
2014-04-15, 05:02 PM,
#6
PM me your Team Viewer I'll get in and help you, it's kinda weird here...
Reply


Possibly Related Threads...
Thread Author Replies Views Last Post
  Aeonsofts VB.NET Theme Manager v2.1 lanzye 32 10,337 2017-10-28, 04:51 PM
Last Post: waiphyoe
  So You Want to Build a Ch@t Bot – Here's How (Complete with Code!) SwiffJustus 0 317 2017-10-05, 09:56 AM
Last Post: SwiffJustus
  I will try to code a bot for you for FREE blacksploit 30 2,543 2017-09-02, 11:49 PM
Last Post: blacksploit
  Best method to learn to code instagramteam 10 2,344 2017-06-02, 11:01 PM
Last Post: Cupcake1337
  [REQUEST] Comment box with moderation HTML code iamrichsoon 1 760 2016-12-25, 05:51 AM
Last Post: CegaFin





About Us | Contact Us | CPA Elites | Advertise | Stats | Staff Team

© 2013-2017 CPA Elites Ltd
Enhanced by MyBB and WallBB
Return to top