Dear Members of the Forum.
I wish to know how to write a For Next loop, that only works in a single instance.
Here is what i am working with, as of late:
!! Thanks in advance !!Code:Dim a As Integer
a = 0
For a = 1 to 1
.
.
.
Next a
Printable View
Dear Members of the Forum.
I wish to know how to write a For Next loop, that only works in a single instance.
Here is what i am working with, as of late:
!! Thanks in advance !!Code:Dim a As Integer
a = 0
For a = 1 to 1
.
.
.
Next a
If you have a hardcoded start value which is equal to the end value then you don’t need a for next loop.
Just assign your variable to the start value
you don't need For Next Loop for a single instance.
the handler keeps on firing up, on the multipul file extractions of the resource file. which i only want the first one in the library resource file. to work on at a single instance moment in time, if that is possible. then why wouldn't it, be then possible???
if u want a function to just be used 1 time,
u can add "Static"..
Static OneTime as Boolean
Dim a As Integer
if OneTime = False then
For a = 1 to 1
.
.
.
Next a
OneTime = True
end if
and if u want to be able to "reset" it
Sub MyFunction(Optional Byval Reset As Boolean)
If Reset Then OneTime = False
Thanks dude, for the input, so
I'm working on something that looks like this:
Code:Option Explicit
'
Dim PauseTime, Start, Finish, TotalTime
Dim strBuff As String
Dim m_Marker As Byte
Static OneTime As Boolean
Dim a As Integer
'
Public Property Get Marker() As String
On Error Resume Next
m_Marker = m_Marker
End Property
Public Property Let Marker(ByVal New_Marker As String)
On Error Resume Next
m_Marker = New_Marker
PropertyChanged "Marker"
End Property
Private Sub UserControl_Initialize()
On Error Resume Next
1 If OneTime = False Then
For a = 1 To 1
If a = 0 Then
a = 0
a = a + 1
PauseTime = 6
Start = Timer
Do While Timer < Start + PauseTime
DoEvents
Loop
Finish = Timer
TotalTime = Finish - Start
If TotalTime = 0 Then GoTo 2
2 strBuff = StrConv(LoadResData("EP" & a, "VIDEO"), vbUnicode)
Open "C:\Temp\zVideo-1234567890.mkv" For Output As #1
Print #1, strBuff
Close #1
PauseTime = 6
Start = Timer
Do While Timer < Start + PauseTime
DoEvents
Loop
Finish = Timer
TotalTime = Finish - Start
If TotalTime = 0 Then GoTo 3
3 If a = 11 then m_Marker = "B"
strBuff = ""
OneTime = True
Else
Exit Sub
End If
Next a
Else
Exit Sub
End If
End Sub
Private Sub UserControl_Resize()
On Error Resume Next
With UserControl
.Height = 330
.Width = 435
End With
End Sub
Private Sub UserControl_ReadProperties(PropBag As PropertyBag)
On Error Resume Next
With PropBag
m_Marker = .ReadProperty("Marker", "")
End With
End Sub
Private Sub UserControl_WriteProperties(PropBag As PropertyBag)
On Error Resume Next
With PropBag
Call .WriteProperty("Marker", m_Marker, "")
End With
End Sub
the code is so strange and just wrong.
a will never and can never be 0 it will always start as 1.Code:For a = 1 To 1
if a = 0 Then
if you want to run 2 times, u should instead do:
would run it once.Code:For a = 0 To 1
if a = 0 Then
if you instead do:
it will loop infinitely. 1>0>1>0 etc.Code:For a = 1 To 1
a = 0
Next a
I assume theres something between this 2 lines right? otherwise it makes no sense.Code:If TotalTime = 0 Then GoTo 2
2
also, UserControl_Initialize is only run once.
if u want to make it global (if u have multiple instances of the class) you will need a public variable outside the class.
so in a module: Public RunOnlyOnce as Boolean
Why are you just setting m_Marker to itself and not returning anything from a property get? Why is the property a string but m_Marker a Byte? This makes no sense at all.
So if m_Marker is a Byte why does the property accept a string which you directly assign to a byte?
What on earth are you trying to do here? Why are you trying to loop only once - that isn't a loop. Why do you have such a convoluted way of checking and setting the variable a? Especially as it will never be 0 in the first place!
Why are you doing a pause immediately? You haven't done anything that needs a pause yet, but you are pausing. You are also doing a pause the worst way (DoEvents in a loop), and then doing a check which will take you to the same place regardless as label "2" immediate follows this code!
A mkv file is a binary file, why are you writing out a string in this case?
Another bad delay that has a pointless If ... Goto that will not alter the code flow
How will "a" ever be 11? Why are you assigning a string to a byte again?
I have no idea what the code is trying to do but it sems to make no sense at all. Why do you think you need a loop to do something once?
Hmmm.. So you are telling it A=1 then you are checking to see if A=0 even though you have just set it to 1Code:For a = 1 To 1
If a = 0 Then
a = 0
a = a + 1
You then if say if A=0 then let's set A=0 then let's set A=A+1 which since you just set it to 0 means you are setting it to 1 but it already was set to one just a couple of lines before.
Makes me wonder if you have ever written a working line of code before.
Then you have these wierd gotos like
Again that if ... goto does nothing the code will always goto line 2 because that is the next line same for the one you have that goes to line 3 Very strange.Code:If TotalTime = 0 Then GoTo 2
2 strBuff = StrConv(LoadResData("EP" & a, "VIDEO"), vbUnicode)
That entire loop will basically do nothing at all and I use the term loop very lightly as it is not really a loop at all either since it will never loop it can't really be called a loop.
This code would do the same thing as the code you have shown for that sub
Code:Private Sub UserControl_Initialize()
End Sub
Look at his other posts...there you will find the answer! ("No")Quote:
Makes me wonder if you have ever written a working line of code before.
ThEiMp is living in a parallel universe, where all laws and logic is scattered around in total chaos.
nothing makes sense for us. but for him, we are the strange ones.
The thing with this snippet of source code is to only proceed if the value of TotalTime = 0. however if the value of TotalTime isn't equal to 0, then it will exit the loop and then only work with the value, when and only when it equals zero, then so. this is set in stone, because of the DoEvents command, found inside the loop, in the above block of source code, of mine. And then also, i have written the line of code, whch is m_Marker = "B". This means for Director to then move to the B Marker of the score window.Code:If TotalTime = 0 Then GoTo 2
2 blah blah
That isn't what your code does though, at no point do you exit the loop and the goto achieves nothing! Why do you think it will exit the loop?
I don't think the DoEvents command does what you think it does, it certainly has nothing to do with exiting loops....
That doesn't make much sense either, it also doesn't explain why the Marker property Get is completely wrong, or why you are mixing string and byte data types.
i just used a wizard for the creation of the m_Marker property, then so
Im starting to suspect ThEiMp is just a fake account from some member here playing a joke on everyone.
I mean the absurdity is extreme. he joined 2007 and the level is below a newbie. Its negative. how can u even get at that level?
JFYI, from his sig:
Quote:
Do you wish to do unpaid work for me??? If so, the PM me on this Forum, and then we can get to work, programming for the future of computers go by the name of ThEiMp. This is my ghost writers name. Also my nickname, means that I am: The Imperial of the Technology Industry. . .
Yes, it explains that he modified the code, without knowing what he is doing or what the implications are
Maybe the Moderators can take a look at this joker and do something about it???
I always thought this posting account was a broken and failed chatbot AI. Literally everything is nonsensical from it.
I'm heading for retirement in the next 3-4months, I won't miss these Thread(s)
what is wrong with this account of mine, it's works like i work at my workplace, then so
Then so! Even So. Fatso.
We also didn't match up against this little bug in my source code, then so???
Code:Dim m_Marker As Byte
Public Property Get Marker() As String
On Error Resume Next
m_Marker = m_Marker
End Property
Public Property Let Marker(ByVal New_Marker As String
On Error Resume Next
m_Marker = New_Marker
PropertyChanged "Marker"
End Property
Red: you should NOT mix Byte and String like that. use "THE SAME"Code:Dim m_Marker As Byte
Public Property Get Marker() As String
On Error Resume Next
m_Marker = m_Marker
End Property
Public Property Let Marker(ByVal New_Marker As String)
On Error Resume Next
m_Marker = New_Marker
PropertyChanged "Marker"
End Property
Blue: Please LOOK CAREFULLY. why assign a value from the same variable. ITS WRONG.
Purple: REMOVE. this will only make your code work but you don't SEE the error. YOU SHOULD NOT USE On Error like that.
thanks for the input
You didn't finish your sentence with "even so", is there something wrong, even so?
This ended once with "so."
"Even so, then so, also then so", or just plain "even" or "then" followed explanations.
"Then so" was used once in confusion, and the end of a following question within the same paragraph. The word "matey" smoothed the transition.
"So" and "so then" followed questions a couple of times, but "so then" also followed explanations, ending once with "guys!" :thumb:
"At that" was used a few times, but it has been retired like good-old "even." :(
"Otherwise so" was used once, but that could've been due to brain farts!
I also found "thus far as so," which felt like a discovery at the Mariana Trench!
I had a little time on my hands. :bigyello:
You are a right so-and-so.
There must be something in the OP's native language that adds these little grammar-farts to the end of sentences. Perhaps they have some subtle influence on the sentence that gives it all meaning, a meaning that we, mere English speakers, are missing.
OP - the reason we draw attention to this is because large parts of your sentences have errors. If you remove these "add-ons" from each sentence, it should (theoretically) improve our understanding.
Input, output, kaput!
oh brother!!
okay, i am reading you
Thanks dudes, you were good help for me to get my single instance for ... next statement block, to be written right. This has been achieved and then now i am going to mark this thread, resolved, then so
Okay then here it is, like so:
Code:Option Explicit
'
Dim PauseTime, Start, Finish, TotalTime
Dim strBuff As String
Dim m_Marker As Byte
Dim OneTime As Boolean
Dim a As Integer
Dim b As Integer
'
Public Property Get Marker() As Byte
On Error Resume Next
m_Marker = m_Marker
End Property
Public Property Let Marker(ByVal New_Marker As Byte)
On Error Resume Next
m_Marker = New_Marker
PropertyChanged "Marker"
End Property
Private Sub UserControl_Initialize()
On Error Resume Next
1 If OneTime = False Then
For a = 1 To 1
b = 0
b = b + 1
PauseTime = 6
Start = Timer
Do While Timer < Start + PauseTime
DoEvents
Loop
Finish = Timer
TotalTime = Finish - Start
If TotalTime = 0 Then GoTo 2
2 strBuff = StrConv(LoadResData("EP" & b, "VIDEO"), vbUnicode)
Open "C:\Temp\zVideo-1234567890.mkv" For Output As #1
Print #1, strBuff
Close #1
PauseTime = 6
Start = Timer
Do While Timer < Start + PauseTime
DoEvents
Loop
Finish = Timer
TotalTime = Finish - Start
If TotalTime = 0 Then GoTo 3
3 If b = 11 Then m_Marker = "B"
strBuff = ""
OneTime = True
Next a
Else
Exit Sub
End If
End Sub
Private Sub UserControl_Resize()
On Error Resume Next
With UserControl
.Height = 330
.Width = 435
End With
End Sub
Private Sub UserControl_ReadProperties(PropBag As PropertyBag)
On Error Resume Next
With PropBag
m_Marker = .ReadProperty("Marker", "A")
End With
End Sub
Private Sub UserControl_WriteProperties(PropBag As PropertyBag)
On Error Resume Next
With PropBag
Call .WriteProperty("Marker", m_Marker, "A")
End With
End Sub
Does that really work as intended? You have still left a lot of the issues in there that were previously pointed out to you...
just a few, I have added comments to the code itself
There still seems to be a lot of potential problems, and I still don't see how a loop that runs only once by design makes any sense....Code:Option Explicit
'
Dim PauseTime, Start, Finish, TotalTime 'Did you mean to use variants?
Dim strBuff As String
Dim m_Marker As Byte
Dim OneTime As Boolean
Dim a As Integer
Dim b As Integer
'
Public Property Get Marker() As Byte
On Error Resume Next ' why? this is dangerous normally, pointless here
m_Marker = m_Marker 'This achieves nothing, a Get should return something as well.
End Property
Public Property Let Marker(ByVal New_Marker As Byte)
On Error Resume Next ' why? this is dangerous normally, pointless here
m_Marker = New_Marker
PropertyChanged "Marker"
End Property
Private Sub UserControl_Initialize()
On Error Resume Next 'This is going to hide any errors in this sub, probably not a good idea!
1 If OneTime = False Then 'Label 1 is never used anywhere, this is the only place OneTime is referred to and will always be false so no need for the If statement anyway
For a = 1 To 1 'How is this any different to not having a loop though?
b = 0
b = b + 1 'Why not just set b = 1, as this is never going to execute more than once
PauseTime = 6
Start = Timer
Do While Timer < Start + PauseTime
DoEvents
Loop 'Busy loops like this are normally a bad idea
Finish = Timer
TotalTime = Finish - Start
If TotalTime = 0 Then GoTo 2 'Does nothing, it would go to the next line anyway.
2 strBuff = StrConv(LoadResData("EP" & b, "VIDEO"), vbUnicode) 'Treating binary data as a string???
Open "C:\Temp\zVideo-1234567890.mkv" For Output As #1
Print #1, strBuff
Close #1
PauseTime = 6
Start = Timer
Do While Timer < Start + PauseTime
DoEvents
Loop 'Busy loop again
Finish = Timer
TotalTime = Finish - Start
If TotalTime = 0 Then GoTo 3 'Again does nothing as it would go to the next line anyway
3 If b = 11 Then m_Marker = "B" 'how will it ever be 11 if you start and 1 and only run the loop once? Also Marker is a byte, why are you assigning a string?
strBuff = ""
OneTime = True
Next a
Else
Exit Sub
End If
End Sub
Private Sub UserControl_Resize()
On Error Resume Next 'Hiding potential errors
With UserControl
.Height = 330
.Width = 435
End With
End Sub
Private Sub UserControl_ReadProperties(PropBag As PropertyBag)
On Error Resume Next 'Hiding potential errors
With PropBag
m_Marker = .ReadProperty("Marker", "A") 'm_Marker is a Byte, why assign a string / character?
End With
End Sub
Private Sub UserControl_WriteProperties(PropBag As PropertyBag)
On Error Resume Next 'Hiding potential errors
With PropBag
Call .WriteProperty("Marker", m_Marker, "A")
End With
End Sub
But then it works, right for the time being, then
So.
:wave:
In cargo cult programming it is OK to have code that has no sense as long as the program works.
Perhaps I tend to be a bit obsessive about these things... I know that no code is likely to be perfect, we all make unintentional mistakes; but I could never just ignore code with blatant mistakes and problems.
The thought of deliberately writing code that is hard to read, contains pointless conditionals that don't change the code flow, getters that don't return anything, control initialisers that are potentially writing out massive video files and not actually doing any control initialisation, etc. just goes against everything I have learned and practiced over the past thirty something years.
Yes, I know, and I agree. But I mean that there are some people that don't want to understand programming, just want things that work and don't care how or why.
Right, but if you look at the threads the OP has created over the past many, many years, they often are him asking for feedback or suggestions on his code, him getting a tremendous amount of suggestions, and him implementing exactly zero of them.
My conclusion is, he's probably just doing the best he can...