Fixed-length strings in .NET structures


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 4 of 4

Thread: Fixed-length strings in .NET structures

Hybrid View

  1. #1
    Join Date
    May 2004
    Location
    barcelona-spain
    Posts
    38

    structures in NET

    Public Structure header_mia

    Public eti1 As String '* 8

    Public NUM_OREC As Long

    Public padding1 As Long

    Public eti2 As String '* 8

    end structure

    I am unnable to translate this into a visualbasic net type as net do not accept string *8,for example, inside the structure
    This was a nice type of data and now I need help to use it.

  2. #2
    Join Date
    Nov 2003
    Location
    Portland, OR
    Posts
    8,387
    Why do you need String * 8? If it's because you're reading records from/writing to a file, you can do this:

    Public Structure header_mia
    <VBFixedString(8)>Public eti1 As String
    ' ...

    For more information, see http://msdn.microsoft.com/library/en...gattribute.asp
    Phil Weber
    http://www.philweber.com

    Please post questions to the forums, where others may benefit.
    I do not offer free assistance by e-mail. Thank you!

  3. #3
    Join Date
    May 2004
    Location
    barcelona-spain
    Posts
    38

    Thanks

    This is the reason why
    "I need a subrutine to translate wgs84 geographic coordinates to UTM in the ED50 elipsoide (as the CAD files they give to me comes with these coordinates). I college gave me this subrutine for vb6 and as I an upgrading from vb6 to visual studio 2005 this is the reason why I do not find all the information I need at the moment I need. On the other hand I have a big confidence with people like you in the forums. Kind regards."
    Here is the full subrutine and I still need to learn how to read from a binary file and the get that is not acepted.
    Is is to much is a beg you to teach us how to cope with this?. I am sure many people would appreciate it.

    "
    Public S_LAT As Double
    Public N_LAT As Double
    Public E_LONG As Double
    Public W_LONG As Double
    Public LAT_INC As Double
    Public LONG_INC As Double
    Public GS_COUNT As Long
    Public cabeceras() As String
    Public NUM_OREC As Long
    Public NUM_SREC As Long
    Public NUM_FILE As Long
    Public GS_TYPE As String
    Public VERSION As String
    Public SYSTEM_F As String
    Public SYSTEM_T As String
    Public MAJOR_F As Double
    Public MINOR_F As Double
    Public MAJOR_T As Double
    Public MINOR_T As Double
    Public nombre As String
    Public Const nrejs As Long = 150


    Public Type nodo
    ilat As Single
    ilon As Single
    plat As Single
    plon As Single
    End Type


    Public Type header_mia
    eti1 As String * 8
    NUM_OREC As Long
    padding1 As Long
    eti2 As String * 8
    NUM_SREC As Long
    padding2 As Long
    eti3 As String * 8
    NUM_FILE As Long
    padding3 As Long
    eti4 As String * 8
    GS_TYPE As String * 8
    eti5 As String * 8
    VERSION As String * 8
    eti6 As String * 8
    SYSTEM_F As String * 8
    eti7 As String * 8
    SYSTEM_T As String * 8
    eti8 As String * 8
    MAJOR_F As Double
    eti9 As String * 8
    MINOR_F As Double
    eti10 As String * 8
    MAJOR_T As Double
    eti11 As String * 8
    MINOR_T As Double
    End Type
    Public Type sub_grid
    eti1 As String * 8
    SUB_NAME As String * 8
    eti2 As String * 8
    PARENT As String * 8
    eti3 As String * 8
    CREATED As String * 8
    eti4 As String * 8
    UPDATED As String * 8
    eti5 As String * 8
    S_LAT As Double
    eti6 As String * 8
    N_LAT As Double
    eti7 As String * 8
    E_LONG As Double
    eti8 As String * 8
    W_LONG As Double
    eti9 As String * 8
    LAT_INC As Double
    eti10 As String * 8
    LONG_INC As Double
    eti11 As String * 8
    GSCOUNT As Long
    padding As Long
    End Type





    Sub et2ed(ByVal lon As Double, ByVal lat As Double, lonf As Double, latf As Double)


    Dim lone0 As Double, late0 As Double, lonw0 As Double, latw0 As Double
    Dim latw As Double, lonw As Double
    Dim x As Double, y As Double, nh As Integer

    lone0 = lon
    lonw0 = lon
    late0 = lat
    latw0 = lat
    For f = 1 To 15
    Call gsbread(lone0, late0, lonw, latw)
    If latw <> 0 Then
    inclat = lone0 - lonw
    inclon = late0 - latw
    If f = 1 Then
    lone0 = lonw0 + inclon
    late0 = latw0 + inclat
    Else
    lone0 = lone0 - (lonw - lonw0)
    late0 = late0 - (latw - latw0)
    End If
    Else
    late0 = 0: lone0 = 0
    Exit For
    End If
    Next f
    latf = late0
    lonf = lone0

    End Sub
    Sub gsbread(ByVal lon As Double, ByVal lat As Double, lonf As Double, latf As Double)

    Dim i(nrejs) As Long
    Dim j(nrejs) As Long
    Dim M(nrejs) As Long
    Dim n(nrejs) As Long
    Dim p(4) As Long
    Dim posicion(nrejs) As Long
    Dim punto(4) As nodo
    Dim cabecera As header_mia
    Dim ggrid(nrejs) As sub_grid

    msel = 1000000

    lon = -lon 'POSITIVE WEST


    Open nombre For Binary As #1
    Get #1, , cabecera

    'Selección de la grid adecuada
    For f = 1 To cabecera.NUM_FILE
    Get #1, , ggrid(f)
    posicion(f) = Seek(1)
    Seek #1, ggrid(f).GSCOUNT * 16 + posicion(f)

    M(f) = 1 + Round((ggrid(f).N_LAT - ggrid(f).S_LAT) / ggrid(f).LAT_INC)
    n(f) = 1 + Round((ggrid(f).W_LONG - ggrid(f).E_LONG) / ggrid(f).LONG_INC)
    i(f) = 1 + Fix((lat - ggrid(f).S_LAT) / ggrid(f).LAT_INC)
    j(f) = 1 + Fix((lon - ggrid(f).E_LONG) / ggrid(f).LONG_INC)

    If i(f) > 0 And j(f) > 0 And i(f) < M(f) And j(f) < n(f) Then 'Rejilla v´alida
    If ggrid(f).LAT_INC < msel Then
    msel = ggrid(f).LAT_INC
    sel = f
    End If
    End If

    Next f

    If sel <> 0 Then 'Ha sido seleccionada alguna rejilla
    p(1) = n(sel) * (i(sel) - 1) + j(sel)
    p(2) = p(1) + 1
    p(3) = p(1) + n(sel)
    p(4) = p(3) + 1

    For ij = 1 To 4 'Lectura de los nodos
    Seek #1, posicion(sel) + (p(ij) - 1) * 16
    Get #1, , punto(ij)
    Next ij
    lata = ggrid(sel).S_LAT + (i(sel) - 1) * ggrid(sel).LAT_INC
    lona = ggrid(sel).E_LONG + (j(sel) - 1) * ggrid(sel).LONG_INC
    y = (lat - lata) / ggrid(sel).LAT_INC
    x = (lon - lona) / ggrid(sel).LONG_INC
    'COEFICIENTES
    a0 = punto(1).ilat
    a1 = punto(2).ilat - punto(1).ilat
    a2 = punto(3).ilat - punto(1).ilat
    a3 = punto(1).ilat + punto(4).ilat - punto(2).ilat - punto(3).ilat
    ip = a0 + a1 * x + a2 * y + a3 * x * y
    latf = lat + ip

    b0 = punto(1).ilon
    b1 = punto(2).ilon - punto(1).ilon
    b2 = punto(3).ilon - punto(1).ilon
    b3 = punto(1).ilon + punto(4).ilon - punto(2).ilon - punto(3).ilon
    ib = b0 + b1 * x + b2 * y + b3 * x * y
    lonf = lon + ib

    End If

    Close #1




    lonf = -lonf 'POSITIVE WEST
    End Sub

    Sub rgs2(ByVal r As Double, gg As Double, mm As Double, ss As Double)
    'Entran las cosas en segundos
    'function [gg,mm,ss]=rg(r)
    pi = 4 * Atn(1)

    ap = 100000
    If r < 0 Then
    signo = -1
    Else
    signo = 1
    End If
    r = Abs(r)

    r = r / 3600

    grados = Fix(r)
    minutos = Fix((r - grados) * 60)
    Min = ((r - grados) * 60)
    segundos = ((Min - minutos) * 60)

    If Round(segundos * ap) / ap >= 60 Then
    minutos = minutos + 1
    segundos = segundos - 60
    End If
    If Round(minutos * ap) / ap >= 60 Then

    grados = grados + 1
    minutos = minutos - 60
    End If
    If Round(grados * ap) / ap >= 360 Then

    grados = grados - 360
    End If


    ss = segundos
    mm = minutos
    gg = grados



    End Sub
    "

  4. #4
    Join Date
    Nov 2003
    Location
    Portland, OR
    Posts
    8,387
    Phil Weber
    http://www.philweber.com

    Please post questions to the forums, where others may benefit.
    I do not offer free assistance by e-mail. Thank you!

Similar Threads

  1. Replies: 0
    Last Post: 06-29-2005, 05:30 PM
  2. .NOT vs .NET
    By Robert Lantry in forum .NET
    Replies: 88
    Last Post: 04-05-2002, 08:03 AM
  3. Classic vs. NET again - sorry!
    By Mark Gonzales in forum .NET
    Replies: 14
    Last Post: 03-04-2002, 10:28 AM
  4. Thoughts on Net verses VB7
    By Don Jones in forum .NET
    Replies: 71
    Last Post: 04-19-2001, 04:02 AM
  5. vs7 and dot net
    By pasu in forum .NET
    Replies: 2
    Last Post: 03-23-2001, 12:39 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center