Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
 
  HOME    TRACKER    Visual Basic




PivotField Text Limit


Does anyone know if there is any way to view more than 255 characters in a pivot table field?

i have created a database in excel for users to write comments, which are then viewed/sorted via a pivot table. The problem is that some people have written entries with more than 255 characters. Excel is truncating the entries in the pivot table results, although the full text is still in the original spreadsheet.
Is there a default that I can change, or is it a limitation of the Pivot table?




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
PivotField Selection Problems!!!
Hi all,

Can anyone help. I have this code to create a pivot table on a seperate sheet in my workbook. The problem is i want to be able to change the pivotfield ranges below by being able to correspond to a point on the worksheet i.e. activecellranger1c1 or cell A1..etc.. At the moment if iwant to change the datafield and row field it is manually done in VB Editor.

Thanks!!!

Code:
ActiveCell.FormulaR1C1 = "I want this to appear"


.PivotFields Range("I want this to appear !!!HERE!!!").Orientation = xlDataField
.PivotFields Range("I want this to appear !!!HERE").Orientation = xlRowField


Sub CreatePivotTable()
Dim PTCache As PivotCache
Dim PT As PivotTable

On Error Resume Next
Application.DisplayAlerts = False
Sheets("Summary").Delete
On Error GoTo 0

Set PTCache = ActiveWorkbook.PivotCaches.Add _
(SourceType:=xlDatabase, _
SourceData:="Source Data!R1C1:R3000C20") _

Worksheets.Add
ActiveSheet.Name = "Summary"
ActiveCell.FormulaR1C1 = "I want this to appear"


Set PT = PTCache.CreatePivotTable _
(TableDestination:=Sheets("Summary").Range("b22"), _
TableName:="PivotTable1")
ActiveWindow.Zoom = 75
ActiveWindow.DisplayGridlines = False

With PT
.PivotFields Range("I want this to appear !!!HERE!!!").Orientation = xlDataField
.PivotFields Range("I want this to appear !!!HERE").Orientation = xlRowField
.PivotFields("Function").Orientation = xlPageField
.PivotFields("Location").Orientation = xlPageField


End With


End Sub

Moving To The Next Item In A Pivotfield
I have some code which runs in this For loop.


Code:
For Each PivotItem In ActiveSheet.PivotTables("PivotTable1").PivotFields("Questions").PivotItems
Sheets("Pivot Table").Select
Range("A4").Select
Range(Selection, Selection.End(xlToRight)).Select
Selection.Copy
Sheets("Chart Data").Select
ActiveCell.Select
ActiveSheet.Paste
Sheets("Pivot Table").Select
Selection.End(xlDown).Select
Range(Selection, Selection.End(xlToRight)).Select
Selection.Copy
Sheets("Chart Data").Select
ActiveCell.Offset(1, 0).Select
ActiveSheet.Paste
ActiveCell.Offset(3, 0).Select

Next

The item "Questions" is in the page field at the top.

I'd like the code to move to the next item in the page field, and perform the code.

Any idea how it's done?

Coloring Pivotfield.item
Hi guys,

I would like to prepare code which will color pivotfield.pivotitem.labelrange. So far I have prepared the following code:



VB Code:
Dim pvtfield As PivotFieldDim pvtitem As PivotItemsSet pvtfield = ActiveSheet.PivotTables("PivotTable9").PivotFields("year2_sk")For Each pvtitem In pvtfieldpvtitem.LabelRange.Interior.ColorIndex = 24Next


When I run this code it giving me back the 438 error code and highlights me the 4th line.
Can anybody tell me what is wrong?

Thanks. Boris


I have changed to this and it works:


VB Code:
Dim pvtfield As PivotFieldDim pvtitem As PivotItemDim i, jSet pvtfield = ActiveSheet.PivotTables("PivotTable9").PivotFields("year2_sk")i = pvtfield.PivotItems.CountFor j = 1 To i  pvtfield.PivotItems(j).LabelRange.Interior.ColorIndex = 24  pvtfield.PivotItems(j).LabelRange.Font.Bold = True  pvtfield.PivotItems(j).LabelRange.HorizontalAlignment = xlCenterNext j

Pivot Table; Loop Through PivotField Values
I’m new to this, but I’ll give it a shot. I’m trying to create a macro that will look at a list and iterate all of the values through a PivotField. I can get this to work if I write the specific value needed in the PivotField into the macro, but not a way to cycle through all of the values without naming them.

For example, a PivotField "NEW_USED" with 2 values "New" and "Used":

Sheets("Amort").Select
ActiveSheet.PivotTables("PivotTable1").PivotFields("NEW_USED").Current Page = _
"NEW"
ActiveSheet.PivotTables("PivotTable1").PivotFields("NEW_USED").Current Page = _
"USED"

Any help would be appreciated.

Limit The Text??
how to limit the numbers or characters that be inputed in the text box???

tnx for help

Text Box Character Limit
Maybe I am just over looking the option, but is there a way that I can set the text box so it will only allow the user so many characters to be typed in a certain text box?

Email Text Limit
I am sending an email via VB using the shell command and I have run into a problem where the default emailer wont open, in this case outlook express. I have narrowed down the problem that if the message in the body is too large it will not open up the default emailer.

Has anyone ever ran into this problem? Anyone know the text limit of sending an email message with the shell command.

I am using the following code.

VB Code:
Public Sub Email(hWnd As Long, Address As String, Optional Subject As String, _            Optional Body As String, Optional CC As String, Optional BCC As String)    ShellExecute hWnd, _        "open", _        "mailto:" & Address & _        "?cc=" & CC & _        "&bcc=" & BCC & _        "&subject=" & Subject & _        "&body=" & Body, vbNullString, vbNullString, _        SW_SHOWEnd Sub

Character Limit In Text Box?
Is there a limit to the amout of text that you can enter into a text box? If so does anyone know what it is? Thanks

Limit Text Box To Min 1 Digit And Max 2
limit text box to min 1 digit and max 2 ie 9 or 22
thanx

Limit Textbox To Text Only
How do you limit a textbox to only accept letters? I don't want the user to be able to enter numbers or symbols.

Is it possible to set it to a text-only box?

Textbox Text Limit?
Hi,

I have a textbox that is filled on run-time (textbox.text = "....")
It seems that if I have lots of data, not all the data is inserted into the textbox - Do you know for any limitation of its length or something like that?

My textbox control is "multiline"

Thanks!

Limit Text Box In Userform To 1 Character
Can i limit a text box to only being allowed 1 letter in a userform?

Using code similar to this:


Code:
Private Sub txtAge_Change()
Dim Str As String, I As Integer

On Error Resume Next

Str = txtAge.Text
I = Len(Str) - 1

If Not (IsNumeric(Str)) Or (I > 1) Then
txtAge.Text = Left(Str, I)
End If
End Sub



But i want it for 1 letter, not numerical.

How To Limit The Number Of Rows In A Text Box
Please tell me how can i limit the number of rows in a multiline text box.

Limit The Number Of Lines In A Text Box
Can someone tell me how to limit the number of lines in a text box? I want to limit the number of lines, the user can enter into a multiline textbox. Say 20 lines and not let them enter any more than that.

Text Box Size Limit Problems
I am outputting data to a text box for live view of incoming informaton. I am also logging the information to a text file so the user can print out the data when all the logging is finished. The problem is the text box stops writing information after about 500 lines. The log file which is a text file will log all the information which is approximately 2000 lines. Does anyone know how to make the text box allow for more lines or any other way to display 2000 lines of information with a scroll bar? Thanks for your time

Text Box Limit For Storing Info
Hi all,

I am wondering if text box control has some limits to store strings.

For example, assuming that text box control is used in a server application to give information about what is going on client's side, like:

Somewhere in the code;


Code:
txtLog.Text = txtLog.Text & vbCrLf & Now() & "> " & "Yeni Baglanti: " & RtIndex & ", " & RtIP

I think there must be an upper limit that the text box control can handle.

EpcH

PS: Knowing that maybe that server will be online for days without shutting it down.

Need To Limit Text Box Input To Numbers...how?
I would like to limit text box input to numbers only...the value in the text box is being used for calculations and needs to be double precision.

Is there a standard way to block input of all but numbers and a "."?

My program crashes whenever a letter is typed in the box and the calculate button is pushed...

Limit Number Of Characters In A Text Box
I need to limit a textbox to 250 chars, because anything over 255 will crash the database, the only way i can do it doesnt seem to work correctly, because i need to check the lengthof the copy/pastes into it as well.
Basically i need to make it so there is no way on earth that they could enter more than 250 characters. Any ideas?

Character Limit On Text Boxes
Is there a way of applying a limit to the number of characters that can be put in a text box in VB 6. Also how would I display an error message if the user tries to go over the word limit?

Thanks,
Darren

Question About Textboxes And Their Max Text Limit
is there anyway to set a textbox's text ignoring the max text limit?

Winsock.. Limit On Text Length?
Is there a limit to how much data can be sent in 1 string? or is it just the limit of the string variable itself? if so what is that since i can't remember? if not and it is a limit on the winsock control itself.. what is that?

Is There A Character Limit To Text Boxes?
Hi all, i'm working on a text editor in VB6. My problem starts when i open really large text files within my program. Part of the file get's cut off when the data is sent to the text box. I thought that maybe there was just some sort of data limit to the text box so i started using a richtextbox. Now it works fine... all the text is there but now i have a problem with the horizontal scroll bar. I have both scroll bars turned on but the horizontal scroll bar is never used even though i can see it. The text just get's wrapped automatically to the next line... this really sucks because it screws up all the formatting. I checked to see if there was an option within the control to turn of wordwrapping in the richtextbox but i see nothing.. am i blind?
Basically i would really like to go back to using a regular texbox so as to keep things simple and avoid formatting characters that may be introduced into the files.. my editor is intended to be a c or c++ editor so junk characters can really play havoc when it comes time to compile.
By the way i have the MaxLength property on my text box set to 0.. this means there should be no limit as to how much data i can display right? But still the text is cut off.
I can really use the help guys, Thanks in advance!

Limit Text Line Length
I'm writing a program that creates File_ID.diz files and want to limit each line to the standard 45 characters and wrap to the next line without breaking up the words. Anyone know how?
Thanks

Limit Length Of Text In Textbox
i know this must be simple, but i haven't been able to find the answer in any of my books. i would like to limit the number of characters allowed in a textbox to 50.
thank you in advance.

Limit Text And Read Write To Db
Hi im a HNC Computing Student at Motherwell College i need a few codes. I have given a project to do for to pass this course.Its a Student Regisation forum.

I need a Code that lets the user put in a thing like this AA0010 From the AA0000 to ZZ9999

But it has to have 2 letters and 4 numbers not over that. Its for a Student Code for the project. I need a code that will prevet the user entering more that the above. I have it has a textbox. and it has to link to the database.

Also need a code that the user can't put more than 5 numbers in the telephone part.

Raiders

Vb6: How To Limit The Number Of Chars In A Multiline Text Box??
Hi All,
I have a multiline textbox that I want to limit the number of characters to 22. When 22 chars are entered in each every line, the cursor will then enter a new line (vbcrlf) and continues the typing. The pattern should be looks like as follow:

1234567890123456789012
3456789012345678901234
5678901234567890123456
7890123456789012345678
9012345678901234567890
...

DIM mintLineCount AS INTEGER

Private Sub txtNature_KeyPress(KeyAscii As Integer)

Const cLineChars = 22

If mintLineCount = 0 Then
If Len(txtNature) <> 0 And Len(txtNature) Mod cLineChars = 0 Then
txtNature = txtNature & vbCrLf
txtNature.SelStart = Len(txtNature)

mintLineCount = mintLineCount + 1
End If
Else
If Len(txtNature) Mod (cLineChars + mintLineCount) = 0 Then
txtNature = txtNature & vbCrLf
txtNature.SelStart = Len(txtNature)

mintLineCount = mintLineCount + 1
End If
End If

End Sub

I can make it work for 2 lines only. Any one can help??

B Rgds,
Kenny

Character/Line Limit When Searching For Text?
I've written an editor program that uses a RTB for the primary text area. I added a form for text searches that calls the following subroutine:


Code:
Public Sub TextSearch()
Dim Search As String
Dim Where As Integer

With frmOFPBriefEditor
Search = frmFindReplace.txtFFindWhatText.Text
Where = .rtbOFPBriefEditor.Find(Search, 1, -1)
If Where Then
.rtbOFPBriefEditor.SelStart = Where - 1
.rtbOFPBriefEditor.SelLength = Len(Search)
Else
MsgBox "Text not found." ' Notify user.
End If
End With
End Sub
My problem is that when I search larger files (100kb or so) it will give me a run-time error 6.

However, when I search smaller files, the text search will have no problem at all.

A good example is when I search a file with 118197 characters, 5484 lines. I manually searched (scrolled down) for a word that first appears at character 110955, line 5131.

If I try searching for that same word using the above code, I get the run-time error 6.

If I were to copy and paste only 30 lines (as an example) of the text that contains the word I was originally searching for, then it finds the word no problem, and with no error.

My question is this:

Is there a limit on how big of a file that can be searched successfully? If so, is there a better way of writing a text search than what I use above?

I got the basic gist of the search code from the MSDN that came with VB6 Pro and I modified it to meet my needs.

I thank you in advance for your time and for any assistance that anyone can help me with.

Text Replacement Character Limit + VB6 And Word
Hello Pples,

I have created a simple text search and replace program in VB using the word object model. It works well but not when replacemet variable exceeds 250 characters. I get an Runtime error 'string parameter too long'.
This is the sub for replacement:

Sub myReplace()

With oWord.Selection.Find
.ClearFormatting
.Replacement.ClearFormatting
.Text = Question
.Replacement.Text = qText
.Forward = True
.Execute Replace:=wdReplaceAll
End With

End Sub

so when qtext exceeds 250 characters I get error. Somebody heelp me what I should do for such a case.
Please help!

Thanks in advance.
-Prof Dr Afs

RichTextBox Control - Limit Text To Size Of Box
Can this be done? I can't find a way to limit the amount of text entered into a RichText control to what will fit in the viewable box. Any ideas will be greatly appreciated. Remember, RTF allows multiple fonts and sizes, so the MaxLength parameter won't work. Thanks.

Limit Length (lines) Of Text File
I have an instant messenger program and that logs each users logs separatly. I need to these files to only allow so many lines so they dont grow out of conrtrol.
Any examples on how this can be accompished?
right now its just appending each entry.

Any help is appriciated.
thanks
Garrett

How To Limit Text Box Character Entries To NUMBERS Only??
How can I make is so that a user can only enter numbers in text boxes?

Thanks

Simple: How To Limit Text Field Size
In order for me to keep from getting garbage in my database, how do I limit the string size of a textbox and make the cursor move to the next tabindex after that limit has been exceeded by the user? This is for things like phone numbers, initials, and such that have a specified, constant length of characters.

Thanks in advance

Long Text File To Excel Database - Row Limit
Hi guys,

I am currently experiencing a problem opening a text file which has the following data in it.
1) X co-ordinates in the first half
2) Y co-ordinates in the second half

I thought it would have been very easy to just copy and paste but seems like there is a Row Limit in Excel and i have too many points - 69041 to be exact ... so thats 69041 x 2 rows !

The Row Limit on Excel seems to be at 65536 ....

Its easy enough to just split the x co-ordinates in 2 as they are incrementing, but the y co-ordinates are all over the place so its hard to know where i left off !

And not only that i have to do the same thing to more than 40 text files with differing number of data points

So i was hoping to write a VB macro to
1) simply count how many rows there are in total
2) Divide it in two and process it so its in a column format
ie from
1
2
3
4
2
2.1
-1
10

to
X Y
1 2
2 2.1
3 -1
4 10

3) to divide them in 2 or 3 or 4 more columns depending how many rows there are (as it cant go above 65536)
4) and then finally to convert it into an Excel file.

I am so far out of my depth since I have no idea what I'm doing I will include a sample of the text document that im trying to convert

I'd appreciate any help you guys can give me

Cheers !

Limit Length Of Text1.text Based On Size Of TextBox?
It's been a while since I've posted in these forums, though I'm still at work on Faux-INN, my VB online games network. If you'de like you can check it out at my website.

One of the most important aspects of Faux-INN is the way the interfaces are handled - for example, the bulletin boards look like real bulletin boards. Every player can build a custom 'avatar' that looks like they do, and when you're playing an opponent in Chess, you can actually *see* who you're playing with.

I've already added e-mail (which you can view by clicking on a 'post office'), but I want to make the input not look like a regular text box, but actually look like a page of a real letter; so you can only fit so much text on a given page.

I can subclass the textbox so it looks like a 'real' page; that's not the problem. My question is... if I have a textbox of a set size, can I put limits on the amount of text you can enter into the textbox, so that you can only enter as much text as could 'fit' in the box, without scrolling?

Thanks much!

How Can I Limit The Number Of Child Document Windows In A Text Editor
Good Morning Everyone!

I have a text editor with an MDI. It's possible to have dozens of child windows open by repeatedly clicking "New" on the toolbar.

How can I limit that number to two or three?

(Code examples are always appreciated!)

Thanks.

Wendy

Limit Text In A Text Box...
Hey all,

I have a friend who is trying to design a template in word for a form. They want to be able to only type a certain number of characters in a text box. This is not possible with a normal text box, so i showed them how to put a VBA text box in and set the MaxLength property. Now the problem is, they want the form to look nice, as in 'fully justified'.

Is this possible in a VBA text box.

If not, i said they could design a form (using vba, with vba textboxes), and then click on a button which updates another template, containing normal word textboxes, and then fully justify them.

Is this the only way? and if so, how to i refer to a normal text box in word, through vba?

Thanks in advance.
Darren

"Insert Into" VB Limit? Ms Access Limit?
Hi guys, I'm still working on the same app as my previous post, but now its a different type of problem. I can now run the SQL statement without an error. But when I try sending items from a list box to the access DB for some reason only 1542 records get added when I know the listbox contains 1629 items.
This is the code that runs
Code:Private Sub cmdSave_Click()
On Error Resume Next

'open connection to be used
dbConOpen

For i = 0 To frmMain.List1.ListCount - 1
    
    List1.ListIndex = i
    'What this does is calls a sub in a module that aquires the ID3 tag of a
    'file with the filepath being under List1.text That would be the list I'm using
    'that lets me know 1629 items are there
    GetID3Tag (List1.Text)
        
   'Year is a reserved word in VB or something so you must put it in brackets for VB to access
   'the SQL statement
   
    sSQL = "Insert Into MP3List (Path,Title,Artist,Album,[Year],Comments,Genre) Values ('"
    sSQL = sSQL & List1.Text & "','"
    sSQL = sSQL & txt(0) & "','"
    sSQL = sSQL & txt(1) & "','"
    sSQL = sSQL & txt(2) & "','"
    sSQL = sSQL & txt(3) & "','"
    sSQL = sSQL & txt(4) & "','"
    sSQL = sSQL & txt(5) & "')"
    
    dbcon.Execute sSQL
      

911:
    If Err.Number = -2147467259 Then
    
        If MsgBox("Could not add " & txt(1) & " " & txt(0) & " " & _
                List1.Text & " to DB. " & _
                "Record already exists", vbOKCancel, "Error") = vbCancel Then
            dbcon.Close
            Exit Sub
        
        End If
                       
    End If
        
Next

dbcon.Close
    
End Sub



Edited by - Huascar82 on 5/28/2004 12:30:20 PM

Was That.. The Limit In I.E?
Greetings!

I just finnished a funny program which can "convert" an image into pure HTML (with the ability to add some CSS for better effects). Then, you can view the result in Internet Explorer and save the result. But as I tested it, I found something that bothered me.

I had an image at a resolution 296 x 407. Since I used "CSS formating" the program told me that the amount of characters would be about 3 600 000 (yay, that's about 3.21 mb). As I convert the image, it writes every whole line to a HTML-file. Of the result, only about 1/6 was shown. The rest was almost black (my background was set to black) with just some few colored characters here and there. Was that the limit in I.E? The rest of the text was still there though, but it had no HTML formating.


Regards!
Pedalen

32K Limit (get #, Put #)
Hi there,
I'm trying to read from and write to a file in binary mode using Open... for Binary, Get # and Put # statements, but VB prompts 'overflow' when the file is larger than 32K.
Does anybody know a way to work around this?

Thanks

Limit?
is there a limit of the number of forms that you can have in a project?

Limit
i'm using JScript to connect to the sql server and for some reason is not allowing me to limit the result

I want to get the last three articles from the table. I'm trying the following code but it comes with an error when I use limit


PHP Code:



sql = "select * from linksC order by ID desc LIMIT 3  "; 

D/L Limit
Download limit
I need to create an application which will keep track of the amount of data that has been downloaded from the internet and when it reaches a certain amount, either completely blocks internet access or reduces the internet speed so that is near unusable anyway.

Oh yes, to make things harder, it uses a shared internet connection on a server; both PCs run Windows XP.

This is all well and good, but I don't know where to start. I would appreciate it if you could suggest some places I could try for information, or provide it yourselves.

Thanks in advance,
Dataphoenyx.

Is There A Limit?
i have an application which is inserting some lines into a multiple line textbox and at the same time running a sql procedure.
now i have the problem that when the textbox has something around 5000 lines there are no more lines added but the sql process continues running.
is it possible that the multiline textbox reached its limit number of lines and that's why it doesn't continue inserting new lines?

If..then...else Limit?
I have about 5 if...then...else statements/functions in one piece of code. Basically, a question is asked. If the answer is yes, then information is given. If the answer is no, then another question is asked etc. At the end of the 5th statement/function, an information message should pop up (if yes) or another question should be asked (if no), but they don't.

I checked Microsoft help and it said you could use these for as many levels as you like, but maybe there's a limit?

64K Limit
There is 64K limit in size of any function, procedure, module, form in VB. Maybe I'm wrong. But this limit is applied for compiled object. How to find out the real size of a form to avoid passing that limit. Checking of size property of a file doesn't give real result, because for example all the comments in a form will not be compiled, but they do affect the size of a form.frm file before compilation.
Any ideas?
Thank you.

2 Gig Limit...
Hello,
I found this info on a class that enables you to read past the 2 gig limit, but I am having trouble in that when I use the readbytes method which I will paste below, it gives me unicode data?? I am not sure how to handle the unicode to format to ASCII. Here is the article....



SUMMARY
When performing low-level random file I/O using the Seek, Get, and Put statements, you are limited to a maximum file size of 2^31 bytes(2 GB). This article provides a sample class for random file I/O that allows access beyond the 2GB limit.



MORE INFORMATION
All file I/O ends up calling low-level Windows APIs, such as ReadFile, WriteFile, and SetFilePointer. The Seek statement calls the SetFilePointer API. This API takes both a low 32-bit value (DWORD) and a pointer to a high DWORD value to indicate a 64-bit position for the next read or write. If the pointer to the high DWORD is NULL (zero), then the API limits the range of values to approximately 2GB.

The class procedure provided in this article provides the following features:



It encapsulates basic functionality for opening, closing, reading, writing, and seeking on files using low-level Windows APIs to get around the 2GB file limit.


It provides basic error trapping.


It currently supports reading and writing byte arrays, but can be easily extended to support other data types.


It exports the file handle, so you can call the APIs natively in your own application, especially if you want to pass User Defined Types (UDTs) to the ReadFile or WriteFile APIs.


The class has the following methods:
IsOpen Returns a boolean to indicate whether the file is open.

OpenFile Opens the file specified by the sFileName argument.

CloseFile Closes the currently open file.

ReadBytes Reads ByteCount bytes and returns them in a Variant byte
array and moves the pointer.

WriteBytes Writes the contents of the byte array to the current
position in the file and moves the pointer.

Flush Forces Windows to flush the write cache.

SeekAbsolute Moves the file pointer to the designated position from the
beginning of the file. Though VBA treats the DWORDS as
signed values, the API treats them as unsigned. Make the
high-order argument non-zero to exceed 4GB. The low-order
DWORD will be negative for values between 2GB and 4GB.

SeekRelative Moves the file pointer up to +/- 2GB from the current
location. You can rewrite this method to allow for
offsets greater than 2GB by converting a 64-bit signed
offset into two 32-bit values.
The class has the following properties:
FileHandle The file handle for the currently open file. This is not
compatible with VBA file handles.

FileName The name of the currently open file.

AutoFlush Sets/indicates whether WriteBytes will automatically call
the Flush method.
Create the Sample Class
Create a new VBA project.


Add a Class Module and set the Class Name to "Random".


Add the following code to the Class Module:


option Explicit

public Enum W32F_Errors
W32F_UNKNOWN_ERROR = 45600
W32F_FILE_ALREADY_OPEN
W32F_PROBLEM_OPENING_FILE
W32F_FILE_ALREADY_CLOSED
W32F_Problem_seeking
End Enum

private Const W32F_SOURCE = "Win32File Object"

private Const GENERIC_WRITE = &H40000000
private Const GENERIC_READ = &H80000000
private Const FILE_ATTRIBUTE_NORMAL = &H80
private Const CREATE_ALWAYS = 2
private Const OPEN_ALWAYS = 4
private Const INVALID_HANDLE_VALUE = -1

private Const FILE_BEGIN = 0, FILE_CURRENT = 1, FILE_END = 2

private Const FORMAT_MESSAGE_FROM_SYSTEM = &H1000

private Declare Function FormatMessage Lib "kernel32" _
Alias "FormatMessageA" (byval dwFlags as Long, _
lpSource as Long, _
byval dwMessageId as Long, _
byval dwLanguageId as Long, _
byval lpBuffer as string, _
byval nSize as Long, _
Arguments as Any) as Long

private Declare Function ReadFile Lib "kernel32" _
(byval hFile as Long, _
lpBuffer as Any, _
byval nNumberOfBytesToRead as Long, _
lpNumberOfBytesRead as Long, _
byval lpOverlapped as Long) as Long

private Declare Function CloseHandle Lib "kernel32" _
(byval hObject as Long) as Long

private Declare Function WriteFile Lib "kernel32" _
(byval hFile as Long, _
lpBuffer as Any, _
byval nNumberOfBytesToWrite as Long, _
lpNumberOfBytesWritten as Long, _
byval lpOverlapped as Long) as Long

private Declare Function CreateFile Lib "kernel32" _
Alias "CreateFileA" (byval lpFileName as string, _
byval dwDesiredAccess as Long, _
byval dwShareMode as Long, _
byval lpSecurityAttributes as Long, _
byval dwCreationDisposition as Long, _
byval dwFlagsAndAttributes as Long, _
byval hTemplateFile as Long) as Long

private Declare Function SetFilePointer Lib "kernel32" _
(byval hFile as Long, _
byval lDistanceToMove as Long, _
lpDistanceToMoveHigh as Long, _
byval dwMoveMethod as Long) as Long

private Declare Function FlushFileBuffers Lib "kernel32" _
(byval hFile as Long) as Long

private hFile as Long, sFName as string, fAutoFlush as Boolean

public property get FileHandle() as Long
If hFile = INVALID_HANDLE_VALUE then
RaiseError W32F_FILE_ALREADY_CLOSED
End If
FileHandle = hFile
End property

public property get FileName() as string
If hFile = INVALID_HANDLE_VALUE then
RaiseError W32F_FILE_ALREADY_CLOSED
End If
FileName = sFName
End property

public property get IsOpen() as Boolean
IsOpen = hFile &lt;&gt; INVALID_HANDLE_VALUE
End property

public property get AutoFlush() as Boolean
If hFile = INVALID_HANDLE_VALUE then
RaiseError W32F_FILE_ALREADY_CLOSED
End If
AutoFlush = fAutoFlush
End property

public property let AutoFlush(byval NewVal as Boolean)
If hFile = INVALID_HANDLE_VALUE then
RaiseError W32F_FILE_ALREADY_CLOSED
End If
fAutoFlush = NewVal
End property

public Sub OpenFile(byval sFileName as string)
If hFile &lt;&gt; INVALID_HANDLE_VALUE then
RaiseError W32F_FILE_ALREADY_OPEN, sFName
End If
hFile = CreateFile(sFileName, GENERIC_WRITE Or GENERIC_READ, 0, _
0, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0)
If hFile = INVALID_HANDLE_VALUE then
RaiseError W32F_PROBLEM_OPENING_FILE, sFileName
End If
sFName = sFileName
End Sub

public Sub CloseFile()
If hFile = INVALID_HANDLE_VALUE then
RaiseError W32F_FILE_ALREADY_CLOSED
End If
CloseHandle hFile
sFName = ""
fAutoFlush = false
hFile = INVALID_HANDLE_VALUE
End Sub

public Function ReadBytes(byval ByteCount as Long) as Variant
Dim BytesRead as Long, Bytes() as Byte
If hFile = INVALID_HANDLE_VALUE then
RaiseError W32F_FILE_ALREADY_CLOSED
End If
ReDim Bytes(0 to ByteCount - 1) as Byte
ReadFile hFile, Bytes(0), ByteCount, BytesRead, 0
ReadBytes = Bytes
End Function

public Sub WriteBytes(DataBytes() as Byte)
Dim fSuccess as Long, BytesToWrite as Long, BytesWritten as Long
If hFile = INVALID_HANDLE_VALUE then
RaiseError W32F_FILE_ALREADY_CLOSED
End If
BytesToWrite = UBound(DataBytes) - LBound(DataBytes) + 1
fSuccess = WriteFile(hFile, DataBytes(LBound(DataBytes)), _
BytesToWrite, BytesWritten, 0)
If fAutoFlush then Flush
End Sub

public Sub Flush()
If hFile = INVALID_HANDLE_VALUE then
RaiseError W32F_FILE_ALREADY_CLOSED
End If
FlushFileBuffers hFile
End Sub

public Sub SeekAbsolute(byval HighPos as Long, byval LowPos as Long)
If hFile = INVALID_HANDLE_VALUE then
RaiseError W32F_FILE_ALREADY_CLOSED
End If
LowPos = SetFilePointer(hFile, LowPos, HighPos, FILE_BEGIN)
End Sub

public Sub SeekRelative(byval Offset as Long)
Dim TempLow as Long, TempErr as Long
If hFile = INVALID_HANDLE_VALUE then
RaiseError W32F_FILE_ALREADY_CLOSED
End If
TempLow = SetFilePointer(hFile, Offset, byval 0&, FILE_CURRENT)
If TempLow = -1 then
TempErr = Err.LastDllError
If TempErr then
RaiseError W32F_Problem_seeking, "error " & TempErr & "." & _
vbCrLf & CStr(TempErr)
End If
End If
End Sub

private Sub Class_Initialize()
hFile = INVALID_HANDLE_VALUE
End Sub

private Sub Class_Terminate()
If hFile &lt;&gt; INVALID_HANDLE_VALUE then CloseHandle hFile
End Sub

private Sub RaiseError(byval ErrorCode as W32F_Errors, _
optional sExtra)
Dim Win32Err as Long, Win32Text as string
Win32Err = Err.LastDllError
If Win32Err then
Win32Text = vbCrLf & "error " & Win32Err & vbCrLf & _
DecodeAPIErrors(Win32Err)
End If
Select Case ErrorCode
Case W32F_FILE_ALREADY_OPEN
Err.Raise W32F_FILE_ALREADY_OPEN, W32F_SOURCE, _
"The file '" & sExtra & "' is already open." & Win32Text
Case W32F_PROBLEM_OPENING_FILE
Err.Raise W32F_PROBLEM_OPENING_FILE, W32F_SOURCE, _
"error opening '" & sExtra & "'." & Win32Text
Case W32F_FILE_ALREADY_CLOSED
Err.Raise W32F_FILE_ALREADY_CLOSED, W32F_SOURCE, _
"There is no open file."
Case W32F_Problem_seeking
Err.Raise W32F_Problem_seeking, W32F_SOURCE, _
"seek error." & vbCrLf & sExtra
Case else
Err.Raise W32F_UNKNOWN_ERROR, W32F_SOURCE, _
"Unknown error." & Win32Text
End Select
End Sub

private Function DecodeAPIErrors(byval ErrorCode as Long) as string
Dim sMessage as string, MessageLength as Long
sMessage = Space$(256)
MessageLength = FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, 0&, _
ErrorCode, 0&, sMessage, 256&, 0&)
If MessageLength &gt; 0 then
DecodeAPIErrors = Left(sMessage, MessageLength)
else
DecodeAPIErrors = "Unknown error."
End If
End Function





Create the Test Sample
Add a Form (Form1) to the project. (Visual Basic creates Form1 by default.)


Add a Text Box (Text1) and 4 CommandButtons to the form with their respective Name and Caption properties set to cmdOpen, cmdClose, cmdRead, and cmdWrite.


Add the following code to the Form:

option Explicit

Dim F as Random

private Sub cmdClose_Click()
F.CloseFile
End Sub

private Sub cmdOpen_Click()
F.OpenFile Text1.Text
End Sub

private Sub cmdRead_Click()
Dim Temp as Variant
F.SeekAbsolute 0, 2 ' Seeks 2 bytes (0*2^32 + 2) = 1 character.
Temp = F.ReadBytes(6)
Debug.print Temp
F.SeekRelative -2 ' Seeks backward 1 character.
Temp = F.ReadBytes(4)
Debug.print Temp
End Sub

private Sub cmdWrite_Click()
Dim B() as Byte
B = "ABCDEFGHI" ' Each unicode character is 2 bytes.
F.WriteBytes B()
End Sub

private Sub Form_Load()
set F = new Random
End Sub

private Sub Form_Unload(Cancel as Integer)
set F = nothing
End Sub





Run the project.


Type a dummy file name into the TextBox, such as c: est.dat.


Click cmdOpen, cmdWrite, cmdRead, and cmdClose (in that order).


RESULT: You should see the following output based on the random positioning prior to reading the written data:
BCD
DE


*****************************************
Now, I have put a test button on my project that I will paste here, when I run this I add a watch to tell me when the value of Temp changes, in the watch box it gives me two values , both chr(82), which is right, in my testfile those two letters are R's. So how do I make Temp contain two actual R's????

Here is my test code...I use the seekabsolute to position myself...it works. The article says readbytes returns a variant byte array, but I don't know how to deal with that.


private Sub cmdTest_Click()
Dim Temp as Variant
Dim rndFile as Random
set rndFile = new Random
rndFile.OpenFile "C: estisp_temp.d00"
rndFile.SeekAbsolute 0, 2
Temp = rndFile.ReadBytes(2)
rndFile.CloseFile
set rndFile = nothing
Debug.print Temp
End Sub




Thanks for any help,
Sean

ListCount Limit???
I am using the following code with my form:

dim totfilecount as Long
totfilecount = File1.ListCount
I know totfilecount will be limited to 2,147,483,647

my question is : Is there a known limit to this listcount where there will be errors given , if so what is it? and is there a way to avoid this?
I will be working with very large numbers of files.

Thanks

.txt File Limit
I am running a test and writes that test data in one output (.txt) file. my automated test can run for whole day. so, can anyone tell me what is the maximum size of *.txt file ?

Because right now, after some time my .txt file get stopped being edited. and if so, whats the other option to save all test data on output files?

Copyright © 2005-08 www.BigResource.com, All rights reserved