Thanks for all help.

My friend have a little problem with a text file.

as follows


He have it to load
as folows

Dim namneng As String, Fnumeng As Long, strLeneng As Long ' för England
Dim iDag As String

Fnumeng = FreeFile
iDag = Format$(Date, "dddd") ', "d")
'Text1.BackColor = RGB(255, 248, 217)
Open App.Path & "\Days.txt" For Input As #Fnumeng
Do Until EOF(Fnumeng)
Line Input #Fnumeng, namneng
If Left$(namneng, 1) = iDag Then
strLen = Len(namneng)
'Text2GR.Text =
' namneng = ConvToStr(Right$(dd, 1))
' Label3eng.Caption = "Idag " '& Left$(iDag, 2) & " " & ConvToStr(Right$(iDag, 2))'''Grekland'
' Label2.Caption = Right$(namngr, strLen - 6)
Label1eng.Caption = Right$(namneng, strLen - 1) '& ConvToStr(Right$(iDageng, 2))
' Label1eng.Caption = namneng
' Label2.Caption = iDag
know he has the problem to link the txt file with idag = format$(Date, "dddd")

IDAG = The day of the date in greece language
he will that the text file should read correct name.
and will be readabeld in a label

Hope some one can help him.

Recommended Answers

All 12 Replies

First of all, it would help for readability to use what are universally accepted variable declarations for variables.

For example, use str at the beginning of a string variable, int at the beginning of an integer, lng at the beginning of a long variable, etc.

strDateGreece as String ' as opposed to iDag as string
lngStrLength as long ' as opposed to strLenEng as long

Experienced programers used to accepted standards could easily mistake your variables for the wrong type.

See if your friend could rewrite this. Then we'll take a closer look at it.

Hi Again

the txtfile is as follows

and hes code is

Dim namneng As String, Fnumeng As Long, strLeneng As Long ' för England
Dim today As String

Fnumeng = FreeFile
today = Format$(Date, "dddd") ', "d")

Open App.Path & "\Days.txt" For Input As #Fnumeng

Do Until EOF(Fnumeng)

Line Input #Fnumeng, namneng

If Left$(namneng, 1) = today Then

strLen = Len(namneng)

Label2.Caption = Right$(namneng, strLen - 6)

know he will that in the text file say FRIDAY be
connected to the right date(dddd) as it is on date$("dddd")
and be visible in an label

I'am not cabael to hel him becasue I'am in Sweden
and he is useing my lapptop.


Here's some sample code. Return the favor someday.

There are some errors in the code. And code for what to do for Greece has not been included. Your friend will have to find the errors and fix them. And he will have to do some thinking about how to deal with the day in Greece.

But this should help y'all out.

Option Explicit
Dim strNameEngland As String, lngFileEngland As Long, strLeneng As Long ' för England
Dim strToday As String
Dim lngStrLength As Long

' strtoday = Format, "dddd") ', "d")

'Do Until EOF(Fnumeng)
'Line Input #Fnumeng, namneng
'If Left$(namneng, 1) = today Then
'strLen = Len(namneng)
'Label2.Caption = Right$(namneng, strLen - 6)

Private Sub cmdOpenFile_Click()
    Dim strArray As String
    Dim strTemp As String
    Dim intCounter As Integer, intDate As Integer, intFileDate As Integer
    intDate = Weekday(Date, vbMonday)
    lngFileEngland = FreeFile
    Open App.Path & "\Dani.txt" For Input As #lngFileEngland
    Do Until EOF(lngFileEngland)
        Line Input #lngFileEngland, strArray(intCounter)
        intFileDate = CInt(Left$(strArray(intCounter), 2))
        If intFileDate = intDate Then
            lngStrLength = Len(strArray(intCounter))
            lblDate.Caption = Right$(strArray(intCounter), lngStrLength - 2)
            Exit Do
        End If
        intCounter = intCounter + 1
End Sub

Private Sub Form_Unload(Cancel As Integer)
    Close #lngFileEngland
End Sub

First of all, it would help for readability to use what are universally accepted variable declarations for variables.

They are far from universal.

Experienced programers used to accepted standards could easily mistake your variables for the wrong type.

No we don't... Standards of this type are company or personal standards, not universal. There are many other standards that don't use str, lng, etc. Any of them are acceptable, some are better than others.

Hello Again

in the line 28 ERROR (Expected Array)


Hello Again

in the line 28 ERROR (Expected Array)


Probably because on line 28 you used a command that requires an array and you didn't use one.

1) You didn't use CODE Tags
2) You didn't bother to tell us what line 28 is
we can't very well tell what you did wrong. You'll have to post useful information for our understanding.

commented: Shows understanding in the basic concepts of Visual Basic programming. And based on experience quickly points out valuable insights. +6

I told you there were errors in the code. I left them in there. And you found one. Now you need to fix it. I don't mind helping you. But I just felt that your friend should do some of the work. Nevertheless, WaltP has graciously pointed out the error for you in line 28 which is listed quite clearly in a previous post as the following (see line 28 in previous post): Line Input #lngFileEngland, strArray(intCounter) By the way, did I say that was line 28?

I threw away the code here. Don't need it. But what I had originally considered was storing each line in an array of string: Dim strArray(7) as String. That way you could save each line in the array for future reference within the function. But after seeing the code in action, I determined I didn't need an array. So I removed the array changing strArray(7) to just strArray. Hence, the error I knew would arise, if you tried to run the code as is. Apparently, not only does your friend in Sweden have VB6, you must have Visual Basic also.

At first the original code contained a fixed array of strings ( strArray(7) ) that would hold the days of the week as they were being loaded inside the Do Loop. Since VB6 arrays are by default zero based--meaning the first index starts with 0--this will actually give you 8 days. So, technically you could use strArray(6) and have 7 String variables to use this function.

I did not include code to figure what to do with Greece. I felt your friend should do some work. Nevertheless, WaltP has helped your friend find the error I left in on purpose. And now he has less work to do.

But you'll notice how the declarations for strings, integers, long variables were declared.

I learned this from style from a PDF written in Spanish from a teacher in Mexico. I later learned the same style from a Mastering Visual Basic CD put out by the creators of Visual Basic who more than likely reside in the United States on the West Coast. I have seen similar style used by programmers in Europe. Just thought I would pass along what I thought were good habits taught by established programmers in their profession.

But it helps you to identify what type of variable is being used in your code.

It's good coding practice to set a standard and keep it consistent when writing code.
I just want to encourage him to use good coding practices.

str --> String
lng --> Long
int --> Integer

But by using a consistent style, you can help yourself and others down the road, if others have to read your code.

Your friend was using str at the beginning of a variable that was a Long, i at the beginning of a String Variable. So, personally, I thought that was confusing.

But this is just what I believe good VB programmers typically recommend. C programmers have their own idiosyncrasies for declaring variables. But this is just my opinion. Take it for what it's worth.

But then again. I have only received this recommendation from Microsoft's authors and from a teacher in a school system who was taught by other teachers. Maybe I should consult with somebody with a better background?

Thanks a lot for all help I have recived.

Hi Again from sweden

I just to know if i can use this

Dim MyWeek, MyDay
Dim idag
Dim x
idag = Format$(Date, "dddd")
MyWeek = Array("Monday", "Tusday", "Wednesday", "Thirsday", "Friday", "Saterday", "Sunday")
MyDay = Array("Måndag", "Tisdag", "Onsdag", "Thorsdag", "Fredag", "Lördag", "Söndag")

 Label1.Caption = myweek

Ican't any thing but still learning you never no when you can

Yes, but you'll avoid problems with VB6 if you use the Option Explicit Option. This forces you to declare your variables as a certain type: e.g. integer, single. double, string, date, etc.

Following this practice can save you a lot of headaches down the road.

If you don't use Option Explicit, then if you declare a variable it will be used as what is called a Variant variable. This means you can use this variable for numbers, characters, strings, floating point values, whatever.

You use Option Explicit at the top of the form when you first start a program. Or you can set it in the Tools Menu under the Options SubMenu item.

Check the box that says: Require Variable Declaration.

The program will then complain that you haven't declare a variable as a certain type. But I stress, you must do this when you first start. If you start and then change it later, the program will just ignore the Option Explicit.

Here's a few spelling corrections:

Tuesday --> Not Tusday
Thursday ..> not Thirsday
Saturday --> not Saterday

Thanks for help

I solved it

You're certainly welcome. I knew you could do it.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.