borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2007 Andrea Tincaniborder

AndreaVB | Forum | News | Downloads | Register | Help | Member List | Statistics | Search | PM | Profile

Print This Topic
Previous Topic (Does anyone know how to create a  survey with numbers?)Next Topic (Any new ideas) New Topic New Poll Post Reply
AndreaVB Forum : VB General : How to get min and max values from a flatfile Solved Topic
Poster Message
sam
Level: Graduate

Registered: 06-05-2006
Posts: 12

icon How to get min and max values from a flatfile

Hi, iam newbie to vb.I want to learn vb as fast as ican.so i am struck with one point

Hi,anybody who helps me was quitely appreciated.
The thing is suppose we are having a flat file having all the information regarding the nodes and elements.So here a Node can be made with x,y co-ordinates and an element is made of 4 nodes.So
the problem we have to find the redundant node i.e, a node not used at atleast once in making of an element.

For example take 1,2,3,4 ,5nodes are there
and elements like 1,2,3,4
but for 1st element we take nodes -->2,1,4,5
2nd element we take nodes-->1,4,2,5
3rd element we take nodes-->2,5,1,4
4 th element we take nodes -->5,1,2,4

so here 3 is the redundant node.(as we didnt used atleast once also in making anelement)

So what i need is now i am getting  the redundantnodes but the problem is with in finding the min and max values of x,y that to from excluding the redundant nodes.(so according to our ex here excluding 3rd node and calculating from 1,2,4,5)

For better understanding i am attaching the flat files and also my .vb file so have a glance and have a tinker and reply me...


[Edited by sam on 08-05-2006 at 05:17 AM GMT]

____________________________
Warm Regards
  
     SAM

____________________________
Attached:
project.zip 25 KB (Downloads: 10)

08-05-2006 at 05:10 AM
View Profile Send Email to User Show All Posts | Quote Reply
sam
Level: Graduate

Registered: 06-05-2006
Posts: 12
icon Re: How to get min and max values from a flatfile

Ok then i am attaching my code here.Iam attaching mycode where i had the problem.so kindly look at the code and give me ur replies..

Private Sub cmdcheck_Click()
  
  Dim xMax As Double
  Dim yMax As Double
  Dim xMin As Double
  Dim yMin As Double
  Dim j As Integer
  Dim count As Boolean
  Dim nodes() As node
  Dim maxx As Double
  Dim maxy As Double
  Dim minx As Double
  Dim miny As Double
  Dim nodemax As Integer, i As Integer
  'NodeMax = Exp(NodeMax)
  Dim data As String, Filename As String
  Dim nodeinfo() As String
  Dim intarray() As Integer
  
  Filename = "d:\cafewok1\data1.inp.txt "
    
  Open Filename For Input As #1
        
    Do While Not EOF(1)
       Line Input #1, data
       data = UCase$(Trim$(data))
       If InStr(data, "*NODE") > 0 Then Exit Do
    Loop
  
    Do While Not EOF(1)
       Line Input #1, data
       data = UCase$(Trim$(data))
       If Left$(data, 1) = "*" Then Exit Do
        If InStr(data, ",") > 0 Then
          
         nodeinfo = Split(data, ",")
         nodemax = nodeinfo(0)
'         nodes(1).x = nodeinfo(1)
'         nodes(2).y = nodeinfo(2)
          
'        If nodeinfo(1) > xMax Then xMax = nodeinfo(1)
'        If nodeinfo(2) > yMax Then yMax = nodeinfo(2)
'        If nodeinfo(1) < xMin Then xMin = nodeinfo(1)
'        If nodeinfo(2) < yMin Then yMin = nodeinfo(2)
        End If
      Loop
'      MsgBox ("NodeMax = " & nodemax)

     ' Debug.Print "NodeMax = " & NodeMax & "  xMax = " & xMax & "  yMax = " & yMax
'      MsgBox ("NodeMAx= " & nodemax & " xMax =" & xMax & " yMax = " & yMax & " xMin= " & xMin & " yMin = " & yMin)
'
      'Close #1
      
      ReDim intarray(0 To nodemax) As Integer
        
      Do While Not EOF(1)
      Line Input #1, data
      data = UCase$(Trim$(data))
      If Left$(data, 1) = "*" Then Exit Do
      If InStr(data, ",") > 0 Then
      nodeinfo = Split(data, ",")
      
      intarray(nodeinfo(1)) = 1
      intarray(nodeinfo(2)) = 1
      intarray(nodeinfo(3)) = 1
      intarray(nodeinfo(4)) = 1
      
      End If
      
      Loop
              
     'Close #1
            
      For i = 1 To nodemax
      
      If intarray(i) = 0 Then
      
      MsgBox ("node " & i & " is redundant")
                
      Else

If nodeinfo(1) > xMax Then xMax = nodeinfo(1)
    If nodeinfo(2) > yMax Then yMax = nodeinfo(2)
     If nodeinfo(1) < xMin Then xMin = nodeinfo(1)
     If nodeinfo(2) < yMin Then yMin = nodeinfo(2)
     end If
        
      MsgBox (" xMax= " & xMax & "yMax= " & yMax & " xMin= " & xMin & " yMin = " & yMin)

'   Close #1
      End Sub


The code to find Min and  Max values are persented in the bold.So kindly read my problem fromthe above post  and chesk the bolded code and  reply me as soon as possible.....

____________________________
Warm Regards
  
     SAM

09-05-2006 at 07:11 AM
View Profile Send Email to User Show All Posts | Quote Reply
admin
Level: Administrator


Registered: 04-04-2002
Posts: 530
icon Re: How to get min and max values from a flatfile

I think you should move the check for max/min values inside the cycle for reading the file. try to replace the bold text with this:


      ReDim intarray(0 To nodemax) As Integer
        
      Do While Not EOF(1)
      Line Input #1, data
      data = UCase$(Trim$(data))
      If Left$(data, 1) = "*" Then Exit Do
      If InStr(data, ",") > 0 Then
         nodeinfo = Split(data, ",")
      
         intarray(nodeinfo(1)) = 1
         intarray(nodeinfo(2)) = 1
         intarray(nodeinfo(3)) = 1
         intarray(nodeinfo(4)) = 1

         If nodeinfo(1) > xMax Then xMax = nodeinfo(1)
         If nodeinfo(2) > yMax Then yMax = nodeinfo(2)
         If nodeinfo(1) < xMin Then xMin = nodeinfo(1)
         If nodeinfo(2) < yMin Then yMin = nodeinfo(2)
      
      End If
      
      Loop
              
     'Close #1
            
      For i = 1 To nodemax
      
         If intarray(i) = 0 Then
      
            MsgBox ("node " & i & " is redundant")
                
         Else

            MsgBox (" xMax= " & xMax & "yMax= " & yMax & " xMin= " & xMin & " yMin = " & yMin)
         End If

'   Close #1
      End Sub


____________________________
AndreaVB

10-05-2006 at 07:05 AM
View Profile Send Email to User Show All Posts Visit Homepage | Quote Reply
sam
Level: Graduate

Registered: 06-05-2006
Posts: 12
icon Re: How to get min and max values from a flatfile

Hi, First ofall thanks for ur reply and the thing which i was asked you was notfulfilled sir.So once agian you had a look and get the solution.Plz help me........


Hope u will me,I need your help.

____________________________
Warm Regards
  
     SAM

10-05-2006 at 09:03 AM
View Profile Send Email to User Show All Posts | Quote Reply
admin
Level: Administrator


Registered: 04-04-2002
Posts: 530
icon Re: How to get min and max values from a flatfile

what's happening? did you get wrong Max Min Values? what's exactly the problem? more info please

PS. the example you posted didn't work: Form4.frm is missing

____________________________
AndreaVB

10-05-2006 at 03:30 PM
View Profile Send Email to User Show All Posts Visit Homepage | Quote Reply
sam
Level: Graduate

Registered: 06-05-2006
Posts: 12
icon Re: How to get min and max values from a flatfile

Hi,first of all read my previous messages then you will be having an idea of where i am getting wrong.Bcoz of  frm4 missing i had written my whole code in my message.nope agian i will send u my project file.see my problem is i am getting the redundant nodes,at the same time i have to get the min and max values of x,y of nodes .But the conrol is at the end of the file.So the problem lies there.So you read once my previous posts and have a glance at my project and give me ur reply.I am depending on you.I am also attaching different  txt files..

waiting for your reply
regards


____________________________
Warm Regards
  
     SAM

____________________________
Attached:
Form3.zip 15 KB (Downloads: 2)

11-05-2006 at 05:31 AM
View Profile Send Email to User Show All Posts | Quote Reply
admin
Level: Administrator


Registered: 04-04-2002
Posts: 530
icon Re: How to get min and max values from a flatfile

it seems there was an error in using string values to determinate Max and Min...I've tested this code and it seems to work well:

Option Explicit
    
Private Sub cmdcheck_Click()
    Dim j As Integer
    Dim maxx As Variant
    Dim maxy As Double
    Dim minx As Double
    Dim miny As Double
    Dim nodemax As Integer, i As Integer
    Dim data As String
    Dim Filename As String
    Dim nodeinfo() As Double
    Dim strParams() As String
    Dim intarray() As Integer
  
    Filename = "d:\cafewok1\alum_geo1.txt"
    
    Open Filename For Input As #1
        
    'move to the start of nodes coordinates
    Do While Not EOF(1)
        Line Input #1, data
        data = UCase$(Trim$(data))
        If InStr(data, "*NODE") > 0 Then Exit Do
    Loop
  
    'read until the last node to get the number of nodes
    Do While Not EOF(1)
        Line Input #1, data
        data = UCase$(Trim$(data))
        If Left$(data, 1) = "*" Then Exit Do
        If InStr(data, ",") > 0 Then
            strParams = Split(data, ",")
            nodemax = Val(strParams(0))
        End If
    Loop
      
    ReDim intarray(0 To nodemax) As Integer
        
    'get used nodes
    Do While Not EOF(1)
        Line Input #1, data
        data = UCase$(Trim$(data))
        If Left$(data, 1) = "*" Then Exit Do
        If InStr(data, ",") > 0 Then
            strParams = Split(data, ",")
            intarray(strParams(1)) = 1
            intarray(strParams(2)) = 1
            intarray(strParams(3)) = 1
            intarray(strParams(4)) = 1
        End If
    Loop
              
    Close #1
    'reopen file to determinate max and min based on the used nodes
    Open Filename For Input As #1
    Do While Not EOF(1)
        Line Input #1, data
        data = UCase$(Trim$(data))
        If InStr(data, "*NODE") > 0 Then Exit Do
    Loop
    For i = 1 To nodemax
        If intarray(i) = 0 Then
            Line Input #1, data
            MsgBox ("node " & i & " is redundant")
        Else
            Line Input #1, data
            If InStr(data, ",") > 0 Then
                data = UCase$(Trim$(data))
                strParams = Split(data, ",")
                'redim nodeinfo array with the same bound of the splitted array
                ReDim nodeinfo(LBound(strParams) To UBound(strParams))
                'copy the string value in a double array
                For j = 1 To UBound(strParams)
                    nodeinfo(j) = Val(strParams(j))
                Next
                If nodeinfo(1) > maxx Then maxx = nodeinfo(1)
                If nodeinfo(2) > maxy Then maxy = nodeinfo(2)
                If nodeinfo(1) < minx Then minx = nodeinfo(1)
                If nodeinfo(2) < miny Then miny = nodeinfo(2)
            End If
       End If
    Next
    MsgBox ("Maxx=" & maxx & " Maxy= " & maxy & " Minx= " & minx & " Miny = " & miny)
End Sub
      
Private Sub cmdexit_Click()
    Unload Me
End Sub


hope this helps

____________________________
AndreaVB

11-05-2006 at 06:54 AM
View Profile Send Email to User Show All Posts Visit Homepage | Quote Reply
sam
Level: Graduate

Registered: 06-05-2006
Posts: 12
icon Re: How to get min and max values from a flatfile

HI,Yah u did really wonderful job.thank u very much for caring me  but the min values of both x,y are not  coming.
Also  the nodes starting with  "0 " number (data1.new1.inp.txt)
this file is not working and our program doesnt  finding the redundant nodes for this textfile as it was starting from 0.
So can u say where is the wrong and get the min values of x,y..
please


____________________________
Warm Regards
  
     SAM

11-05-2006 at 09:09 AM
View Profile Send Email to User Show All Posts | Quote Reply
admin
Level: Administrator


Registered: 04-04-2002
Posts: 530
icon Re: How to get min and max values from a flatfile

new code:


Option Explicit
    
Private Sub cmdcheck_Click()
    Dim j As Integer
    Dim maxx As Variant
    Dim maxy As Double
    Dim minx As Double
    Dim miny As Double
    Dim nodemax As Integer, i As Integer
    Dim data As String
    Dim Filename As String
    Dim nodeinfo() As Double
    Dim strParams() As String
    Dim intarray() As Integer
    Dim bFirst As Boolean
  
    Filename = "d:\datanew1.inp.txt"
    
    Open Filename For Input As #1
        
    'move to the start of nodes coordinates
    Do While Not EOF(1)
        Line Input #1, data
        data = UCase$(Trim$(data))
        If InStr(data, "*NODE") > 0 Then Exit Do
    Loop
  
    'read until the last node to get the number of nodes
    Do While Not EOF(1)
        Line Input #1, data
        data = UCase$(Trim$(data))
        If Left$(data, 1) = "*" Then Exit Do
        If InStr(data, ",") > 0 Then
            strParams = Split(data, ",")
            nodemax = Val(strParams(0))
        End If
    Loop
      
    ReDim intarray(0 To nodemax) As Integer
        
    'get used nodes
    Do While Not EOF(1)
        Line Input #1, data
        data = UCase$(Trim$(data))
        If Left$(data, 1) = "*" Then Exit Do
        If InStr(data, ",") > 0 Then
            strParams = Split(data, ",")
            intarray(strParams(1)) = 1
            intarray(strParams(2)) = 1
            intarray(strParams(3)) = 1
            intarray(strParams(4)) = 1
        End If
    Loop
              
    Close #1
    'reopen file to determinate max and min based on the used nodes
    Open Filename For Input As #1
    Do While Not EOF(1)
        Line Input #1, data
        data = UCase$(Trim$(data))
        If InStr(data, "*NODE") > 0 Then Exit Do
    Loop
    bFirst = True
    Do While Not EOF(1)
        Line Input #1, data
        If Left(data, 1) = "*" Then Exit Do
        If InStr(data, ",") > 0 Then
            data = UCase$(Trim$(data))
            strParams = Split(data, ",")
            If intarray(Val(strParams(0))) = 0 Then
                MsgBox ("node " & i & " is redundant")
            Else
                'redim nodeinfo array with the same bound of the splitted array
                ReDim nodeinfo(LBound(strParams) To UBound(strParams))
                'copy the string value in a double array
                For j = 1 To UBound(strParams)
                    nodeinfo(j) = Val(strParams(j))
                Next
                If bFirst Then
                    maxx = nodeinfo(1)
                    minx = nodeinfo(1)
                    maxy = nodeinfo(2)
                    miny = nodeinfo(2)
                    bFirst = False
                Else
                    If nodeinfo(1) > maxx Then maxx = nodeinfo(1)
                    If nodeinfo(2) > maxy Then maxy = nodeinfo(2)
                    If nodeinfo(1) < minx Then minx = nodeinfo(1)
                    If nodeinfo(2) < miny Then miny = nodeinfo(2)
                End If
            End If
       End If
    Loop
    MsgBox ("Maxx=" & maxx & " Maxy= " & maxy & " Minx= " & minx & " Miny = " & miny)
End Sub
      
Private Sub cmdexit_Click()
    Unload Me
End Sub


____________________________
AndreaVB

11-05-2006 at 03:08 PM
View Profile Send Email to User Show All Posts Visit Homepage | Quote Reply
sam
Level: Graduate

Registered: 06-05-2006
Posts: 12
icon Re: How to get min and max values from a flatfile

Hi,yah we were getting now Min and Max vlaues of X,Y.But the logic of redundant nodes are missing now if we check the code the redundant nodes are showing as all zeros.So now without  getting   right redundant nodes how ur getting  the exact min and max values ? Once check the code and also the  file "datanew1.inp.txt" is starting from 0 and all other files r startinf from 1 so is there any logic to work ryt for both cases..please help me .. I am at the end of project..

____________________________
Warm Regards
  
     SAM

12-05-2006 at 04:58 AM
View Profile Send Email to User Show All Posts | Quote Reply
admin
Level: Administrator


Registered: 04-04-2002
Posts: 530
icon Re: How to get min and max values from a flatfile

the last code I posted works well for every case: starting from 0 or 1, or even 2 or 5...why are saying it's not working?

if you look at the code I've replaced the last For...Next looping from 1 to nodemax with a do...loop that exits only when we read the "*"

let me know if everything is ok, and if you say it' not working tell me what it should do that it doesn't...

____________________________
AndreaVB

12-05-2006 at 06:04 AM
View Profile Send Email to User Show All Posts Visit Homepage | Quote Reply
sam
Level: Graduate

Registered: 06-05-2006
Posts: 12
icon Re: How to get min and max values from a flatfile

Hi,No yaar the  redundant nodes are printing like  in message box
" Node 0 is redundant"  where there is no 0 node in the file.And all thru it was  giving "node0 is redundant " for some times.May be the it was giving the exact result of howmany nodes are redundant but the number(i,e 0 is wrong).In palce of zero it shld  print somother numbers.And also for file "dat1anew1.inp.txt"  the  redundant nodes are not  printing.it is directly printing the min and max values.why it was happening like that...So please  go thru once agian to ur code and  help me ...


[Edited by sam on 12-05-2006 at 08:36 AM GMT]

____________________________
Warm Regards
  
     SAM

12-05-2006 at 08:34 AM
View Profile Send Email to User Show All Posts | Quote Reply
admin
Level: Administrator


Registered: 04-04-2002
Posts: 530
icon Re: How to get min and max values from a flatfile

it is now showing redundand nodes because there are no redundand nodes in datanew1.inp.txt

why do you tell node 0 should be redundand? it ir referred by many surfaces
please attach the data file that is giving you strange results...I'll give it a try...

[Edited by admin on 12-05-2006 at 09:56 AM GMT]

____________________________
AndreaVB

12-05-2006 at 08:54 AM
View Profile Send Email to User Show All Posts Visit Homepage | Quote Reply
sam
Level: Graduate

Registered: 06-05-2006
Posts: 12
icon Re: How to get min and max values from a flatfile

Yah ur ryt ,for the file datanew1.inp.txxt dont have the redundant nodes.I was just baffled bcoz i sent u different file and i am having diff file with same name.So its my mistake.I beg pardon for that.ok now for other files the redundant nodes  are not coming  correctly.So once agian look at for other files like (alum_geo.txt,data1.inp.txt e.t.c).

Kindly look ok ..




____________________________
Warm Regards
  
     SAM

13-05-2006 at 04:09 AM
View Profile Send Email to User Show All Posts | Quote Reply
admin
Level: Administrator


Registered: 04-04-2002
Posts: 530
icon Re: How to get min and max values from a flatfile

Oooopppsss,

there was an error in the redundand nodes MsgBox line, replace it with this

MsgBox ("node " & Val(strParams(0)) & " is redundant")


____________________________
AndreaVB

15-05-2006 at 06:29 AM
View Profile Send Email to User Show All Posts Visit Homepage | Quote Reply
samsundar
Level: Whizz Kid

Registered: 13-05-2006
Posts: 16
icon Re: How to get min and max values from a flatfile

Hi,Thank you very much for ur kind co-operation...

[Edited by samsundar on 15-05-2006 at 06:40 AM GMT]

____________________________
Regards

SamSundar

15-05-2006 at 06:39 AM
View Profile Send Email to User Show All Posts | Quote Reply
AndreaVB Forum : VB General : How to get min and max values from a flatfile Solved Topic
Previous Topic (Does anyone know how to create a  survey with numbers?)Next Topic (Any new ideas) New Topic New Poll Post Reply
Surf To:


Not Logged In? Username: Password: Lost your password?
Partners: Download Actual Software | Free Software Download
borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2007 Andrea Tincaniborder