VB School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become a VB Expert!

Join 300,391 VB Programmers for FREE! Get instant access to thousands of VB experts, tutorials, code snippets, and more! There are 1,576 people online right now. Registration is fast and FREE... Join Now!




Problem with increasing

 

Problem with increasing, Canīt increase with loops

The Gothic

26 Jun, 2009 - 05:20 AM
Post #1

New D.I.C Head
*

Joined: 4 Jun, 2009
Posts: 13


My Contributions
Hi,
I have a little problem with increasing. Letīs say we have 000 and we want to count like 001 - 999. How can I reach it with loops? My code does totally something different. Iīm learning loops in the meantime so I donīt know how to use them corretly. Hereīs my actual code:

CODE


Dim a As Integer, b As Integer, c As Integer
Dim res As Variant, prvni As Variant
a = 0
b = 0
c = 0

SendKeys ("~")
y = InputBox("Zadej pocet SSN", "SSN", "25")

Open "C:\Documents and Settings\anovotny\Desktop\loop.xls" For Output As #1

For i = 1 To y
res = a & c & b + i
Write #1, res
Print res

If b + i = 9 Then

For k = 1 To 9
res = a & c + k & b
Write #1, res
Print res

If c + k = 9 Then
For j = 1 To 9
res = a + j & c & b
Write #1, res
Print res

Next j
End If

Next k
End If

Next i

Close #1



Thx for your help

User is offlineProfile CardPM
+Quote Post


Ghostwolf

RE: Problem With Increasing

26 Jun, 2009 - 05:59 AM
Post #2

New D.I.C Head
*

Joined: 1 May, 2009
Posts: 20



Thanked: 2 times
My Contributions
If I understand, you want the output file to contain:
001
002
003
etc

You might try
CODE

dim A as Integer
  For A = 0 to 999
    Print #1, Format(A, "0##")
  Next A

User is offlineProfile CardPM
+Quote Post

Rhymer

RE: Problem With Increasing

26 Jun, 2009 - 09:57 AM
Post #3

New D.I.C Head
*

Joined: 21 Apr, 2009
Posts: 19

Option Explicit

Private Sub Form_Load()
Dim I As Integer
Dim J As Integer
Dim K As Integer
Dim Num As String
For I = 0 To 9
For J = 0 To 9
For K = 0 To 9
rem Num = I & J & K will work due to coercion but properly should use:
Num = trim(Str$(I)) & trim(Str$(J)) & trim(Str$(K))
rem or alternatively: num=replace(num," ","") to get rid of spaces between
Debug.Print Num
rem you write or print to other destination here
Next
Next
Next
End Sub
User is offlineProfile CardPM
+Quote Post

Fib

RE: Problem With Increasing

26 Jun, 2009 - 10:08 AM
Post #4

D.I.C Head
**

Joined: 12 Mar, 2009
Posts: 71



Thanked: 6 times
My Contributions
Hi The Gothic

In your code you have:

CODE
Open "C:\Documents and Settings\anovotny\Desktop\loop.xls" For Output As #1


CODE
Write #1, res


Just to let you know, you cannot write to excel files this way. If you must write your data to an excel file, there is a way but it involves a little bit more complicated code.
User is offlineProfile CardPM
+Quote Post

The Gothic

RE: Problem With Increasing

30 Jun, 2009 - 12:51 AM
Post #5

New D.I.C Head
*

Joined: 4 Jun, 2009
Posts: 13


My Contributions
Hi Fib,
yes. There is one problem. I write output to .xls file indeed but with wrong cell formating.

And thanks guys for your codes. It helped me a lot
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic

Time is now: 11/7/09 09:47PM

Live VB Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

VB Tutorials

Reference Sheets

VB Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month