Click here to Skip to main content
16,006,013 members
Home / Discussions / Visual Basic
   

Visual Basic

 
AnswerRe: How to get Binary File into XML and then back Pin
Dave Kreskowiak13-Jul-07 3:52
mveDave Kreskowiak13-Jul-07 3:52 
QuestionCapture the cell contents in a datagridview Pin
steve_rm13-Jul-07 1:38
steve_rm13-Jul-07 1:38 
QuestionRe: Capture the cell contents in a datagridview [modified] Pin
steve_rm13-Jul-07 2:00
steve_rm13-Jul-07 2:00 
Questioninputbox Pin
md_refay13-Jul-07 1:12
md_refay13-Jul-07 1:12 
AnswerRe: inputbox Pin
Johan Hakkesteegt13-Jul-07 2:56
Johan Hakkesteegt13-Jul-07 2:56 
QuestionVB6 webbrowser "run-time error -1 (ffffffff)" Pin
a.vehbi13-Jul-07 1:00
a.vehbi13-Jul-07 1:00 
AnswerRe: VB6 webbrowser "run-time error -1 (ffffffff)" Pin
Dave Kreskowiak13-Jul-07 3:44
mveDave Kreskowiak13-Jul-07 3:44 
QuestionLogic for file splitting? Pin
sudhakar7913-Jul-07 0:46
sudhakar7913-Jul-07 0:46 
Hi,

Requirement is like, splitting a big text file into small files based on max and min sizes, these max and min sizes, we will pass as orguments to the file splitter function.

the condition is, all the files sizes after splitting should be in between max and min sizes.

Can any one help me out.


Here is my code, but some cases it is failing.


Public Class cFileSplit
'Dim File_size_in_MB As Long = FileLen("C:\Load sub directory\sample.txt")

Dim info As Byte() = New Byte(-1) {}
Dim bytes As Integer = 0
Dim flag As Integer
Dim remainder As Integer = 0

Private Function TextFileSplit(ByVal sFileName As String, ByVal liSize As Long) As Boolean
Dim File_size_in_MB As Long = FileLen(sFileName)
Dim File_size_in_MB1 As Long
Dim iFilecounter As Integer
Dim oFile As File
Dim oFileInfo As FileInfo
Dim tmpOutfilename As String
'Dim sfileout As File
Dim oWrite As StreamWriter
Dim oRead As StreamReader
Dim MaxSize As Long = liSize
Dim MinSize As Long = 100
Dim obj As New cFileSplit

Try
'open the file from the txtFiletoSplit textbox
oFileInfo = New System.IO.FileInfo(sFileName)
tmpOutfilename = oFileInfo.FullName.Replace(oFileInfo.Extension, "").ToString & "_" & iFilecounter.ToString & oFileInfo.Extension
oRead = oFileInfo.OpenText()
oWrite = File.CreateText(tmpOutfilename)
Do While oRead.Peek <> -1

If bytes >= MaxSize AndAlso flag = 1 Then
oWrite.Flush()
oWrite.Close()
iFilecounter += 1
bytes = 0
File_size_in_MB = File_size_in_MB - MaxSize
'set the new filename
tmpOutfilename = oFileInfo.FullName.Replace(oFileInfo.Extension, "").ToString & "_" & iFilecounter.ToString & oFileInfo.Extension
'open the new file
oWrite = File.CreateText(tmpOutfilename)

ElseIf bytes >= MinSize AndAlso flag = 2 Then
oWrite.Flush()
oWrite.Close()
iFilecounter += 1
bytes = 0
File_size_in_MB = File_size_in_MB - MinSize
flag = 3
'set the new filename
tmpOutfilename = oFileInfo.FullName.Replace(oFileInfo.Extension, "").ToString & "_" & iFilecounter.ToString & oFileInfo.Extension
'open the new file
oWrite = File.CreateText(tmpOutfilename)
ElseIf bytes >= File_size_in_MB AndAlso flag = 4 Then
oWrite.Flush()
oWrite.Close()
iFilecounter += 1
bytes = 0
File_size_in_MB = 0
'set the new filename
tmpOutfilename = oFileInfo.FullName.Replace(oFileInfo.Extension, "").ToString & "_" & iFilecounter.ToString & oFileInfo.Extension
'open the new file
oWrite = File.CreateText(tmpOutfilename)
End If
'Write a line to the file from the file we are reading
'While File_size_in_MB > MaxSize

If File_size_in_MB > MinSize Then

If File_size_in_MB - MaxSize > MinSize Then
Dim lsline1 As String = oRead.ReadLine()
oWrite.Flush()
oWrite.Write(lsline1)
oWrite.WriteLine()
info = New UTF8Encoding(True).GetBytes(lsline1)
bytes = bytes + info.Length
flag = 1
Else
If File_size_in_MB - MinSize >= MinSize Then
Dim lsline2 As String = oRead.ReadLine()
oWrite.Flush()
oWrite.Write(lsline2)
oWrite.WriteLine()
info = New UTF8Encoding(True).GetBytes(lsline2)
bytes = bytes + info.Length
flag = 2
If File_size_in_MB > MinSize AndAlso flag = 3 Then
Dim lsline3 As String = oRead.ReadLine()
oWrite.Flush()
oWrite.Write(lsline3)
oWrite.WriteLine()
info = New UTF8Encoding(True).GetBytes(lsline3)
bytes = bytes + info.Length
flag = 4
End If
Else
If File_size_in_MB > MinSize Then
Dim lsline3 As String = oRead.ReadLine()
oWrite.Flush()
oWrite.Write(lsline3)
oWrite.WriteLine()
info = New UTF8Encoding(True).GetBytes(lsline3)
bytes = bytes + info.Length
flag = 4
End If
End If
End If
End If
Loop
Catch ex As Exception
Throw ex
Finally
'now close all the open files
oWrite.Flush()
oWrite.Close()
oRead.Close()

oWrite = Nothing
oRead = Nothing
oFile = Nothing
oFileInfo = Nothing
End Try
Return True
End Function

Public Shared Sub Main()

Dim obj As New cFileSplit
obj.TextFileSplit("C:\Load sub directory\sample.txt", 200)
End Sub
End Class
End Namespace



Thanks and Regards,
sudhakar venati,
Mob: 0 984 55 989 71.

AnswerRe: Logic for file splitting? Pin
Dave Kreskowiak13-Jul-07 3:41
mveDave Kreskowiak13-Jul-07 3:41 
GeneralRe:Here is the detailed problem and failing conditions. Pin
sudhakar7913-Jul-07 6:02
sudhakar7913-Jul-07 6:02 
AnswerRe: Logic for file splitting? Pin
Guffa13-Jul-07 3:48
Guffa13-Jul-07 3:48 
GeneralRe:Hi just look at these cases and conditions Pin
sudhakar7913-Jul-07 6:04
sudhakar7913-Jul-07 6:04 
AnswerRe:Hi just look at these cases and conditions Pin
Guffa13-Jul-07 7:53
Guffa13-Jul-07 7:53 
QuestionPaging a DataList? Pin
rashadaliarshad13-Jul-07 0:34
rashadaliarshad13-Jul-07 0:34 
AnswerRe: Paging a DataList? Pin
Dave Kreskowiak13-Jul-07 3:37
mveDave Kreskowiak13-Jul-07 3:37 
QuestionHow can i update custom document properties... Pin
koolprasad200313-Jul-07 0:01
professionalkoolprasad200313-Jul-07 0:01 
Questionmultiple items dragging and dropping from one list box to another listbox.? Pin
sudhakar7912-Jul-07 23:56
sudhakar7912-Jul-07 23:56 
AnswerRe: multiple items dragging and dropping from one list box to another listbox.? Pin
Dave Kreskowiak13-Jul-07 3:29
mveDave Kreskowiak13-Jul-07 3:29 
GeneralRe: Your logic is not working? Pin
sudhakar7915-Jul-07 19:12
sudhakar7915-Jul-07 19:12 
GeneralRe: Your logic is not working? Pin
Dave Kreskowiak16-Jul-07 2:03
mveDave Kreskowiak16-Jul-07 2:03 
GeneralHere is the code... Pin
sudhakar7916-Jul-07 2:54
sudhakar7916-Jul-07 2:54 
GeneralRe: Here is the code... Pin
Dave Kreskowiak16-Jul-07 13:25
mveDave Kreskowiak16-Jul-07 13:25 
Questionwhat is the problem with this code Pin
chiyankrishna12-Jul-07 23:32
chiyankrishna12-Jul-07 23:32 
AnswerRe: what is the problem with this code Pin
Guffa12-Jul-07 23:42
Guffa12-Jul-07 23:42 
GeneralRe: what is the problem with this code Pin
Vasudevan Deepak Kumar13-Jul-07 0:05
Vasudevan Deepak Kumar13-Jul-07 0:05 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.