Home All Groups Group Topic Archive Search About

Help converting a vb6 function to vbnet.

Author
2 Jun 2010 2:10 AM
Sara
Hello,

I am new to vbnet and have only worked with text files thus far. I've
converted the ENC() & Encode() calls from this function already. Any
help would be much appreciated.

=========
Private Sub uuencode(ByVal filename1 As String, ByVal filename2 As String)
        Dim portion_size As Integer

        portion_size = 45

        'open the original file as binary read
    Open (filename1) For Binary Access Read Shared As #1

        'open the target file as binary write
    Open (filename2) For Binary Access Write As #2

        'for standard uuencode compatibility
    Put #2, , "begin 644 " + plain_filename(filename1) + vbCrLf

        'total number of full sized portion with "portion_size" bytes
        total = LOF(1) \ portion_size

        'remain hold the remaining bytes toward end of file
        remain = LOF(1) Mod portion_size

        'prepare instring to read "portion_size" bytes at a time
        instring =  String(portion_size, 0)

        'current file position
        current = 1

        'for loop to read the portion one by one

        For i = 1 To total
              Get #1, current, instring

            'use the ENC() for standard uuencode compatibility, pad "M"

                    Put #2, , ENC(portion_size) + Encode(instring) + vbCrLf
            current = current + portion_size
        Next

            instring = String(remain, 0)

        'get the remaining bytes toward end of the file
            Get #1, current, instring$

        'get the remaining bytes size and calculate ENC() for the last line

            Put #2, , ENC(LOF(1) - current + 1) + Encode(instring) + vbCrLf

            Close #1

        'put "end" for standard uuencode compatibility

            Put #2, , ENC(0) + vbCrLf + "end" + vbCrLf
            Close #2
    End Sub

Author
2 Jun 2010 11:29 AM
Armin Zingler
Am 02.06.2010 04:10, schrieb Sara:
>
>
> Hello,
>
> I am new to vbnet and have only worked with text files thus far. I've
> converted the ENC() & Encode() calls from this function already. Any
> help would be much appreciated.
>
> =========
> Private Sub uuencode(ByVal filename1 As String, ByVal filename2 As String)
>         Dim portion_size As Integer
> [...]

I can't offer a translation service here. ;-)  BTW, all microsoft.public
groups will be closed within the next days, weeks or month.

To upgrade code, one should know the source and destination language.
I guess you will want to write more VB.Net code. Therefore I suggest
you'll study the documentation about file I/O, first. Then you'll also
be able to translate your function.

"File and Stream I/O":
http://msdn.microsoft.com/en-us/library/k3352a4t%28VS.90%29.aspx

I'm pretty sure you'll find such a function in the WWW, however
I'll give some hints:

>         portion_size = 45
>
>         'open the original file as binary read
>     Open (filename1) For Binary Access Read Shared As #1

- Use an IO.FileStream for file access. You can also pass the access level
  to it's constructor.
- Use a BinaryWriter or a StreamWriter to write into the stream.
- Use a BinaryReader or a StreamReader to read from the stream.
- A Streamwriter can use a specificed (text) encoder to write
  Strings into the file. Use System.Text.Encoding.ASCII in this
  case. An alternative is implementing your encoder as a
  sub class of System.Text.Encoding.

>         'open the target file as binary write
>     Open (filename2) For Binary Access Write As #2
>
>         'for standard uuencode compatibility
>     Put #2, , "begin 644 " + plain_filename(filename1) + vbCrLf
>
>         'total number of full sized portion with "portion_size" bytes
>         total = LOF(1) \ portion_size

LOF() -> FileStream.Length


--
Armin
Author
2 Jun 2010 1:55 PM
Sara
Armin Zingler wrote:

Show quoteHide quote
>Am 02.06.2010 04:10, schrieb Sara:
>>
>>
>> Hello,
>>
>> I am new to vbnet and have only worked with text files thus far. I've
>> converted the ENC() & Encode() calls from this function already. Any
>> help would be much appreciated.
>>
>> =========
>> Private Sub uuencode(ByVal filename1 As String, ByVal filename2 As String)
>>         Dim portion_size As Integer
>> [...]
>
>I can't offer a translation service here. ;-)

Heh, whatever.<g> I figured it out, and now have a nice VB2010 Uuencode
class. Of which, not much exists out there other than 3rd party controls
that often choke when using the 4.0 framework.

Anyway, thanks for your help, and have a nice day.

~Sara
Author
2 Jun 2010 2:58 PM
JB
On 2 June, 06:55, Sara <s...@none.invalid> wrote:
Show quoteHide quote
> Armin Zingler wrote:
> >Am 02.06.2010 04:10, schrieb Sara:
>
> >> Hello,
>
> >> I am new to vbnet and have only worked with text files thus far. I've
> >> converted the ENC() & Encode() calls from this function already. Any
> >> help would be much appreciated.
>
> >> =========
> >> Private Sub uuencode(ByVal filename1 As String, ByVal filename2 As String)
> >>         Dim portion_size As Integer
> >> [...]
>
> >I can't offer a translation service here. ;-)
>
> Heh, whatever.<g> I figured it out, and now have a nice VB2010 Uuencode
> class. Of which, not much exists out there other than 3rd party controls
> that often choke when using the 4.0 framework.
>
> Anyway, thanks for your help, and have a nice day.
>
> ~Sara

Hi Armin,

You said that all microsoft.public groups will be closed shortly.
Do you know why and any potential replacement?

Thanks
JB
Author
2 Jun 2010 3:21 PM
Armin Zingler
Am 02.06.2010 16:58, schrieb JB:
> You said that all microsoft.public groups will be closed shortly.
> Do you know why and any potential replacement?

It's been announced in all groups. In this group the last time on May 19st, 15:48 UTC.

http://groups.google.de/group/microsoft.public.dotnet.languages.vb/browse_frm/thread/3d4b2b1990b8751a


--
Armin