-
Dec 30th, 2011, 11:07 AM
#1
Thread Starter
Addicted Member
[RESOLVED] How to get right date format when write to file
My Decelerations are as follows one for input and one for output:
Code:
Dim BookInDate As Date
Dim BookInDate2(0) As Date
This is the code I am using to write to a file (BookInDates is coming from a Text Box)
I also get a error from this part saying "bad file name or number"
Code:
Open (App.Path & "\BookInDates\" & txtDate.Text) For Output As #1
Write #1, BookInDate
Close #1
The date is currently formatted like so on form load, this makes a range of dates in a ListBox. Now this relates to the Text box in the last bit of code as the text box will allways hold the text of the ListBox's listindex.
Code:
DateFormat = "dddd, dd mmmm yyyy"
x = 100
i = 1
lstCustomers.ListIndex = 0
For d = Date To Date + x
lstDates.AddItem Format$(d, DateFormat)
Next
Please can some one help ?!!?!!! TY!
A subtle thought that is in error may yet give rise to fruitful inquiry that can establish truths of great value. - Isaac Asimov
-
Dec 30th, 2011, 11:18 AM
#2
Re: How to get right date format when write to file
Try removing the parentheses. Also you may want to use Print vs Write. Write may add quotations to strings written to file
-
Dec 30th, 2011, 11:25 AM
#3
Hyperactive Member
Re: How to get right date format when write to file
You should also use FreeFile to get the next available file number instead of hard coding a 1.
-
Dec 30th, 2011, 05:27 PM
#4
Re: How to get right date format when write to file
Problem could be that txtDate.Text may have slashes in it.
Try something like this:
App.Path & "\BookInDates\" & Format$(txtDate.Text,"mm-dd-yyyy")
Last edited by DrUnicode; Dec 30th, 2011 at 05:48 PM.
-
Dec 30th, 2011, 06:49 PM
#5
Frenzied Member
Re: How to get right date format when write to file
i don't know why you do what you do....
why the 2 variables 1 in 1 out
we dont see evidence of any out so how can we comment?
app.path needs an object so the filename is wrong- inappropriate-hence the error message
simple test
goto immediate window type
PRINT APP.PATH and you will get an error -object required
why did you not dim dateformat?
whats the i for?
why do you set the listindex to 0? - the additem will append the dates
did you want to clear the listbox?
lose the $ in format$
there is no $ in
and you cant remove the parathesis ( brackets to you and me) because its a bl**dy function that needs arguments and the spec says they must have them! the only functions that are parenthisis free are those that can have no arguments or all optional arguments!
format (now,"dd/mm/yyy")
what else have you broken
here to talk ( a bit sharply I know )
Last edited by incidentals; Dec 30th, 2011 at 06:54 PM.
-
Dec 30th, 2011, 06:55 PM
#6
Re: How to get right date format when write to file
@ incidentals...
1. App.Path is perfectly fine. It needs no object: MsgBox App.Path
2. There is a $ in Format and there is not. Two functions. Press F2 in IDE and enter Format$ in the search box
3. When I was talking about parentheses, I should have specified the one in the OPEN statement
@seditives. If txtDate is empty/blank, that would cause an error. Ignore the parentheses suggestion; though I wouldn't do it
-
Dec 30th, 2011, 06:57 PM
#7
Frenzied Member
Re: How to get right date format when write to file
I cannot believe that members of some standing do ot know the basic functions that have existed since the dawn of vb and for as long as they have known the language.
I am not perfect
just apparently very long in the tooth and ive seen far too much code asnd taught far too many people
god i am grumpy tonight aren't I
here to talk
-
Dec 30th, 2011, 07:04 PM
#8
Frenzied Member
Re: How to get right date format when write to file
lavolpe
(1) in word 2010 vb tonight just now msgbox app.path ... error 424 - object required!
(2) format$ in search is not a function, format as in format(x,"dd/mm/yy") as descibed excel help word2010
(3) whoops did not even notice them they should have no effect what so ever
but I will check
here to talk (and learn - honestly)
-
Dec 30th, 2011, 07:05 PM
#9
Re: How to get right date format when write to file
Originally Posted by incidentals
...I am not perfect
just apparently very long in the tooth and ive seen far too much code asnd taught far too many people
Maybe just a bit tired?
You probably typed APP.PATH incorrectly. There is always an APP.PATH, it will never fail. Try it again
-
Dec 30th, 2011, 07:09 PM
#10
Frenzied Member
Re: How to get right date format when write to file
nope still does not work!
i have been writing app.path in about 1000 ( under estimate) programs over the years
i specialise in single button processes that work within their working directories ( mostly)
big apps, little buttons, much moolah!
worls for me
here to talk (still awake)
-
Dec 30th, 2011, 07:09 PM
#11
Re: How to get right date format when write to file
Originally Posted by incidentals
lavolpe
(1) in word 2010 vb tonight just now msgbox app.path ... error 424 - object required!
(2) format$ in search is not a function, format as in format(x,"dd/mm/yy") as descibed excel help word2010
(3) whoops did not even notice them they should have no effect what so ever
Huh? This is VB, not VBA. Not all VB commands & functions exist in VBA. Same is true in the reverse
Actually had me confused for a second. Had to check to make sure I was in the right part of the forum
-
Dec 30th, 2011, 07:14 PM
#12
Frenzied Member
Re: How to get right date format when write to file
true not all commands are equal
I write in far too many languages ( not just programming )
but the format function to format the time has always been format no $
all languages are the same to me, the slight variations in parameter positioning and the use of property and methods makes little difference to the abilityto under stand this stuff
I just wish people would stop wanting do a then b and then c and all will be fine
and learned a few of the concepts which will enable them to actually problem solve and program better,
prehaps not smarter but a least, logically
there i go again - my sugars must be through the roof
BTW these are the only refs i have as i am not at home on my own machine - still doing the grandpa stuff with grandchildren
here to talk ( a little more)
-
Dec 30th, 2011, 07:20 PM
#13
Re: How to get right date format when write to file
Originally Posted by incidentals
I cannot believe that members of some standing do ot know the basic functions that have existed since the dawn of vb and for as long as they have known the language
In the future, please don't assume we are incorrect when discussing VB related functions. Sometimes we might be incorrect; but probably not most of the time.
Per VB's Object Browser (F2), here is how Format is defined both with & without the $
Code:
Function Format$(Expression, [Format], _
[FirstDayOfWeek As VbDayOfWeek = vbSunday], _
[FirstWeekOfYear As VbFirstWeekOfYear = vbFirstJan1]) As String
Function Format(Expression, [Format], _
[FirstDayOfWeek As VbDayOfWeek = vbSunday], _
[FirstWeekOfYear As VbFirstWeekOfYear = vbFirstJan1])
There are several string related functions in VB that are written with & without the $. Here are some of them: Format$, Mid$, Left$, Chr$, String$, Space$, and several more
Besides if the $ was incorrect, VB would throw an error. For example, doing this in VB errors: ? Val$(Timer)
Last edited by LaVolpe; Dec 30th, 2011 at 07:32 PM.
-
Dec 30th, 2011, 07:41 PM
#14
Frenzied Member
Re: How to get right date format when write to file
I think we may need to look at which versions we are refering to a little more often
which vb 's object browser BTW?
here to listen ( no machines nearby only MSO2010 to hand )
oops look at he time off to bed
back tommorrow nighty night
-
Dec 31st, 2011, 09:16 AM
#15
Re: How to get right date format when write to file
Does App.Path & "\BookInDates\" already exist?
If not you need to create the path first.
Try this sample code:
Code:
Private Declare Function PathFileExistsW Lib "Shlwapi.dll" (ByVal pszPath As Long) As Long
Private Sub Command1_Click()
Dim FF As Integer
Dim strPath As String
strPath = App.Path & "\BookInDates\"
If Not PathFileExistsW(StrPtr(strPath)) Then
MkDir strPath
End If
FF = FreeFile
Open strPath & txtDate.Text For Output As #FF
Write #FF, BookInDate
Close #FF
End Sub
-
Dec 31st, 2011, 11:45 AM
#16
Hyperactive Member
Re: How to get right date format when write to file
incidentals: Before you argue with established members/experts on this forum, you need to check what you're saying. This forum is for VB6 and earlier. What you are referring to is VBA - Visual Basic for Applications which is a different version of VB that is for creating macros in Microsoft Office. The forum for that is HERE. LaVolpe knows what he is talking about.
-
Dec 31st, 2011, 02:39 PM
#17
Frenzied Member
Re: How to get right date format when write to file
i cannot find any references to format$
but i do kow that a$ forces a to be a string
and the only difference i can see from the object browser if the as string qualifier
all other references i can find ( and remember i am not at home
state format returns a string without need of the n$ do the $ is superfluous unlike the lack of $ in left() and its pals in many variations of other more strictly typed language interpretation
I am of course not a valued expert as my 30 years of coding in too many variations of this language count for nothing as I have not been here on the forum
the forum is a place to discuss and formally argue about in the forums case vb in some form or other
here to talk
-
Jan 1st, 2012, 09:02 AM
#18
Thread Starter
Addicted Member
Re: How to get right date format when write to file
wow I am sorry, I started this forum yesterday and sort of forgot about the whole problem
I have read through the posts and yet again my quote from Issac comes through again.
Any way it looks like a lot of questions need to be answered so I can be on my way with this date thing.
are do this in next post as I need to think about how to best write this. =/
A subtle thought that is in error may yet give rise to fruitful inquiry that can establish truths of great value. - Isaac Asimov
-
Jan 1st, 2012, 09:32 AM
#19
Thread Starter
Addicted Member
Re: How to get right date format when write to file
Ok here we are I think this best explains what the problem is. and before incidentals goes on another rant about "why do you code in this way" or "what the hell is the $ for". I am sorry but this is just the way I code things, as my programs usually become very complex (in code / at least to me) which I like to do as it gives the end user absolute full control over the app. Think of it as just my house style. that and I do not fully understand VB coding at the moment (in fact I am quite a newbie when it comes to programming all together )
Any way back to my problem I am having.
which has slightly changed now as instead of writing to a file with the name being the date, I have decided to make a list of dates in one txt file.
As I am a newbie I haven't completely shut the door on incidentals rants lol if there are some things that anyone wants to point out in the way I am doing things please do. I know that LaVolpe has also done this so TY and are make sure to rate once I have finished.
These are the decelerations I am using to Input and Output the Dates:
Code:
Dim BookInDate As Date
Dim BookInDate2(0) As Date
This is the code I am using to add the date to the file:
the file and directory do already exist, its just a matter of putting the dates into it. the problem I now get is that the dates all come come out like this:
00:00:00
Code:
Open (App.Path & "\BookInDates\ALL DATES.txt") For Append As #1
Print #1, BookInDate
Close #1
The deceleration of BookInDate2(0) is a checking system when the form loads which does have a relative function so don't worry I havn't gone mad
I haven't actually made it yet but it will basically go through the file of dates and take these dates away from the generated list of dates that I have shown in the first code box I posted on this forum.
Ok I think I have pretty much covered the explanation of life the universe and everything so thats anouth please come up with a good answer back to this
Last edited by seditives; Jan 1st, 2012 at 09:36 AM.
A subtle thought that is in error may yet give rise to fruitful inquiry that can establish truths of great value. - Isaac Asimov
-
Jan 1st, 2012, 09:53 AM
#20
Frenzied Member
Re: How to get right date format when write to file
the bookindates are all lined up in the listdates
you need to walk through listdates oputputing a date 1 date at a time
here to talk
-
Jan 1st, 2012, 10:10 AM
#21
Thread Starter
Addicted Member
Re: How to get right date format when write to file
Oh yer I knew I missed out something sorry
Right from the top in plain English Language (no VB or any other coding lang)
This form does have more functions I haven't gone date crazy (at least not yet lol) but are just go through the life and death of the dates.
1) On form load "lstDates" is populated with a variable of dates (100 for tests) which start with the today's date
2) A checking system will then proceed also on form load which will stop the user from choosing a date that has already been chosen previously.
3) once the user has chosen a date and has clicked a "submit" button one of the things that needs to happen is the date that has been chosen will be added into the .txt file which be used by the checking system (step two) on the next use of the form.
the problem is happening at stage 3 where it prints the selected date into the .txt file.
To test I select Friday, 06 January 2012 from the list and enter this.
Now I open the .txt file and find: 00:00:00
Why is this????
here to get a very annoying problem solved
A subtle thought that is in error may yet give rise to fruitful inquiry that can establish truths of great value. - Isaac Asimov
-
Jan 1st, 2012, 10:19 AM
#22
Frenzied Member
Re: How to get right date format when write to file
put a stop at the point you are outputting your dates
and look at whet values you are producing
then step back and put a stop where ever you change the date stuff and look at the value there
once you have the date in the right format
then go forwards again
here to help
-
Jan 1st, 2012, 10:26 AM
#23
Thread Starter
Addicted Member
Re: How to get right date format when write to file
Originally Posted by incidentals
outputting your dates
I think you miss understood there is only one date that is being selected
And once the date is submitted before it Prints "BookInDate" :
Code:
lstDates.Text = BookInDate
A subtle thought that is in error may yet give rise to fruitful inquiry that can establish truths of great value. - Isaac Asimov
-
Jan 1st, 2012, 02:29 PM
#24
Frenzied Member
Re: [RESOLVED] How to get right date format when write to file
my big
ok so what have you written for the submit button press then?
here to talk
-
Jan 2nd, 2012, 10:27 AM
#25
Thread Starter
Addicted Member
Re: [RESOLVED] How to get right date format when write to file
I resolved this now simply by just printing the dates as they are in text form and with out determining them ;]
Code:
Open (App.Path & "\BookInDates\ALL DATES.txt") For Append As #1
Print #1, lstDates.Text
Close #1
seems to work fine and if it ant broken don't fix it as the saying goes lol and don't worry I do know WHY it is now working (I know what you experienced coders are like)
and what do you mean by "my big" ?
A subtle thought that is in error may yet give rise to fruitful inquiry that can establish truths of great value. - Isaac Asimov
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|