|
|
Hi all, don't know if anyone can help with this obscure question. I'm currently busy with a project (for school) involving data compression. We'll only work with plain text files which makes life simpler. The problem: a way to save space we came up with is to chop off one bit off each byte, because for character codes < 128 only 7 bits are needed. I've written code that does this, it converts an input file in chunks of 8 bytes, except it corrupts data (half). Here is the code I'm using:
Compression:
file_name = cdsave.FileName<br />
file_length = FileLen(file_name)<br />
fnum = FreeFile<br />
ReDim bytes(1 To file_length)<br />
Open file_name For Binary As #fnum<br />
Get #fnum, 1, bytes<br />
Close #fnum<br />
Kill file_name<br />
For i = 1 To file_length Step 8<br />
txt = vbNullString<br />
txt2 = vbNullString<br />
For isub = 0 To 7 'bytes to process each time.<br />
If file_length < i + isub Then Exit For<br />
txt = txt & Right$(Format$(Dec2Base(bytes(i + isub), 2), "00000000"), 7)<br />
Next isub<br />
For converttxt = 0 To 6<br />
txt2 = txt2 & ChrW(Base2Dec(Mid$(txt, (converttxt * 8) + 1, 8), 2))<br />
Next converttxt<br />
fnum = FreeFile<br />
Open file_name For Append As #fnum<br />
Print #fnum, txt2;<br />
Close #fnum<br />
Next i<br />
Decompression:
txt = vbNullString<br />
txtInPhase = vbNullString<br />
<br />
intEndFile = FreeFile<br />
<br />
file_name = txtFile.Text<br />
file_length = FileLen(file_name)<br />
fnum = FreeFile<br />
ReDim bytes(1 To file_length)<br />
Open file_name For Binary As #fnum<br />
Get #fnum, 1, bytes<br />
Close #fnum<br />
If Dir(cdSave.FileName) = cdSave.FileName Then Kill cdSave.FileName<br />
For i = 1 To file_length Step 7<br />
txt = vbNullString<br />
txt2 = vbNullString<br />
For isub = 0 To 6 'bytes to process each time.<br />
If file_length < i + isub Then Exit For<br />
txt = txt & Format$(Dec2Base(Format$(bytes(i + isub)), 2), "00000000")<br />
Next isub<br />
For converttxt = 0 To 7<br />
txt2 = txt2 & ChrW(Base2Dec(Mid$(txt, (converttxt * 7) + 1, 7), 2))<br />
Next converttxt<br />
fnum = FreeFile<br />
Open cdSave.FileName For Append As #fnum<br />
Print #fnum, txt2;<br />
Close #fnum<br />
Next i
What happens to the data:
Input: Hello. This is a test string for demonstration purposes.
Output: Ollo. Thigpis a tesq|string for OemonstrOtion purgses.
If someone could take some time to look at this I'd be immensely appreciative. I don't expect anyone to do my work for me, and don't worry, the deadline is still far away.
Paul
-- modified at 6:41 Thursday 15th December, 2005
modified 18-Jul-18 11:59am.
|
|
|
|
|
Paul van der Walt wrote:
[in compression ...]
For converttxt = 0 To 6
txt2 = txt2 & ChrW(Base2Dec(Mid$(txt, (converttxt * 8) + 1, 8), 2))
Next converttxt
Paul van der Walt wrote:
[in decompression ...]
For converttxt = 0 To 7
txt2 = txt2 & ChrW(Base2Dec(Mid$(txt, (converttxt * 7) + 1, 7), 2))
Next converttxt
Change the ChrW() in the above lines to use Chr() . the ChrW() function returns a Unicode character which is mucking up your algorithm.
Paul van der Walt wrote: If someone could take some time to look at this I'd be immensely appreciative. I don't expect anyone to do my work for me, and don't worry, the deadline is still far away.
No problem! Your question is one which we are happy to answer - you have thought about the problem and provided your code, and asked nicely It's a pleasure to help.
...Steve
"Give a man a fish and you've fed him for a day. Teach him how to fish and you've fed him for life." (Translation: I'll show you the way, but not write the code for you.) I read that somewhere once
|
|
|
|
|
Wow, thanks very much, seems to be working pretty much fine now.
Should think about that sort of thing next time; always these stupid little problems. I thought it must be an off-by-one error
Paul
modified 18-Jul-18 11:59am.
|
|
|
|
|
Hello,
I am a .net programmer, i am in a trouble pls help me to find a solution.
? How to setup task scheduler in vb.net,i got some samples from this site but some errors occuring.given below
"C:\Documents and Settings\Administrator\My Documents\Visual Studio Projects\test\Form1.cs(78): The type or namespace name 'ScheduledTasks' could not be found (are you missing a using directive or an assembly reference?)"
my question is any thing that i want add reference or something like that pls give me a detailed solution.
Thanks in advance
alex.
email add->malayilalex@gmail.com
Hello all give me a solution'
alex.
|
|
|
|
|
hi,
I am doing a project currently on .net
I have faced a problem regardin the retreival of data and conversion into the xml format.
MY database consists of a row containg more than the maximum length of characters than specified .so while writing to an XML file the row is getting spliited to another row which is a problem for me
Can anyone help me to make an entire come under one Parent Element node itself
|
|
|
|
|
:-Dhello,
can anybody tell me how to store ms-word document into a SQL-SERVER 2000 (datatype for the column could be image or varbinary)
-- modified at 5:54 Thursday 15th December, 2005
|
|
|
|
|
I would look into the various articles on the internet that show you how to store an image into the DB and do the same thing for the document.
basically just reading in the file as a stream of bytes and storing that data into the DB field then getting the data back out and writing to disk again.
George Carlin wrote:
"Don't sweat the petty things, and don't pet the sweaty things."
Jörgen Sigvardsson wrote:
If the physicists find a universal theory describing the laws of universe, I'm sure the a**hole constant will be an integral part of that theory.
My Blog[^]
|
|
|
|
|
I have a panel with a number of different coloured graphics shapes and I was hoping to be able to click on a shape and retrieve its colour.
Is there any way of doing this?
Thanks
|
|
|
|
|
How are your graphics shapes created? Are they separate objects? Are they created at design time or run time?
Assuming that the graphics shapes are objects that have their color as a property, you could have an event handler that handles all of the objects onClick events. In this event handler, you would examine the Color property of Sender.
If the objects don't have a color property, pehaps you can store the color in the tag property.
I hope this helps.
Roy.
|
|
|
|
|
Roy
Thanks. These are just drawings (circles, rectangles [DrawRectangle] etc) which are drawn at run time on a panel. When they are created I choose a colour to classify them and the easiest thing would be to click on the drawing and to test the colour attribute of the point that was clicked.
There are some pretty simple ways around it but I thought that clicking a point and retrieving its colour would be straightforward and that I was missing something.
Cheers
Wayne
|
|
|
|
|
Hi,
I need to write a program to get data from a serial barcode scanner which is using a serial to ethernet controler. Please let me know How can I write a program in VB using winsock control
Rohith
Systems Engineer
Sri Lanka
|
|
|
|
|
I'm assuming your using VB6. You can find an example here[^].
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
I'm looking for a solution to get the process name running an application. For example, i open a word document to generate a letter. The expected result is WinWord.exe.
I'm using VB .Net for my development.
Very much appreciate if can show me what is the API to use and the sample code.
Thanks a lot.
Heng
|
|
|
|
|
Process.GetProcesses()[^] might be of use to you. It'll return an array of Process[^] objects that you can use to find what you're looking for.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Hi Dave,
Thanks a lot. This is the function i'm looking for and it return the result i want.
Heng
|
|
|
|
|
Hi, trying to learn how to interpret information from WinDbg and ProcessExplorer (from www.sysinternals.com). So, I wrote a simple Win32 console app in VB.NET (could have been anything else really):
Imports TestDebugger
Module Module1
Sub Main()
Functions.SubA(1000, 100)
Functions.SubB(1000, 100)
Functions.SubC(1000, 100)
Return
End Sub
End Module
Imports System.Threading
Public Class Functions
Public Shared Sub SubA(ByVal max As Int32, ByVal sleep As Int32)
For i As Int32 = 1 To max Step 1
Thread.CurrentThread.Sleep(sleep)
Console.WriteLine("SubA: " + CStr(i))
Next i
Return
End Sub
Public Shared Sub SubB(ByVal max As Int32, ByVal sleep As Int32)
For i As Int32 = 1 To max Step 1
Thread.CurrentThread.Sleep(sleep)
Console.WriteLine("SubB: " + CStr(i))
Next i
Return
End Sub
Public Shared Sub SubC(ByVal max As Int32, ByVal sleep As Int32)
For i As Int32 = 1 To max Step 1
Thread.CurrentThread.Sleep(sleep)
Console.WriteLine("SubC: " + CStr(i))
Next i
Return
End Sub
End Class
Now comes the questions:
1. WndDbg - how can I set breakpoint in WndDbg to break at TestDebugger.exe calls to Functions.SubA?
2. ProcessExplorer: Hey I located "TestDebugger.exe", double click and page to "Threads" tab and I couldn't see any calls to .NET Functions.SubA??? how come? Thanks in advance.
I captured the screenshots of information I got running WndDbg and ProcessExplorer.
Norman Fung
|
|
|
|
|
Hi, everybody, I want to make an application in the server that will also run in all clients' background, the application that I want to make it somewhat like a reminder that will load on startup, but is hidden for them, so if the client is scheduled to do something, the applicaton will show pop-up message box, so the client will be alerted, can anyone help me ????
|
|
|
|
|
I have a program, whereby i wish only authorised person can install it. Therefore, i tried to add serial number while i make the installer using Vb.net, however, i cant find the way to add the serial number in... Can anyone please help me to figure out? Thanks a lot..
|
|
|
|
|
NET Installer classes do not execute until the end of the setup sequence, and are not particularly useful for this kind of task. You need to use a custom action DLL that runs during the UI sequence instead.
See here:
http://www.thecodeproject.com/dotnet/msinetserial.asp[^]
|
|
|
|
|
Thanks... your information is so useful.. =)
|
|
|
|
|
now i would like to program the log-in part of the pocket pc, so i should create a database for ppc...right? so how and what codes can be used to create this part?...
thanx
go ahead...do best on my works....
|
|
|
|
|
Hi,
I want to draw formated text obtained from a RichTextBox onto a usercontrol using GDI+. The text from the RTB has more than one font styles while the Graphics.DrawString function from GDI+ can only pass one font-style on each call.
Is there anyone has done it before or has ideas to solve it? please help.
cheers,
Mank
|
|
|
|
|
I want a vb code for testing the printer trays.
vb Program has to find the installed printers, paper formats and the trays on the pc of each printer. It has to find all type of printers (HP, Lexmark, brothers,..)
Example: print some text on paper from a specific tray
\\server\printer1 - has 2 trays.
- tray 1 : A4
- tray 2 : A6
I want to print a text from tray 1:A4 and tray2:A6.
To find the printer and tray, program uses the SystemPrinters dll. But i cannot find a way to make this programm. Any help is excellent.
Rommel
|
|
|
|
|
I need desperate help. I have a status bar with 4 panels and four labels above and outside of the status bar each above a panel. When the panel grows/shrinks with text - need for the labels to resize accordingly with the panels.
This is what I am trying now:
Private Sub ChkPause(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Checkpau.CheckedChanged
If Checkpau.Checked = True Then
'TxtFil_na.Text = "Program Paused " & vbCrLf & "Double Click Here to Start"
TxtFil_na.BackColor = Color.Red
StatusBar.Panels(1).Text = "Program Paused"
Else
TxtFil_na.BackColor = Color.LightGreen
'TxtFil_na.Text = "Program Running "
StatusBar.Panels(1).Text = "Program Runningggggg"
End If
End Sub
Private Sub Form1_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Resize
Dim panelWidth As Integer = Me.StatusBar.Size.Width / 4
lblsz.Width = StatusBar.Panels(0).Width
lblsts.Width = StatusBar.Panels(1).Width
lblFil_na.Width = StatusBar.Panels(2).Width
lblerr.Width = StatusBar.Panels(3).Width
StatusBar.Panels(1).AutoSize = StatusBarPanelAutoSize.Contents
End Sub
|
|
|
|