Results 1 to 15 of 15

Thread: No Longer "Quick Question"........Accessing controls on the main form from a CLASS,

Threaded View

  1. #1

    Thread Starter
    Frenzied Member dinosaur_uk's Avatar
    Join Date
    Sep 2004
    Location
    Jurassic Park
    Posts
    1,098

    Resolved No Longer "Quick Question"........Accessing controls on the main form from a CLASS,

    Hi guys,

    I have a problem .....

    In my module,
    VB Code:
    1. Imports System.IO
    2.  
    3. Module mod_Maths_Functions
    4.     Public CRSC As CRS_Creator.frmMain
    5.  
    6.     Function DeviationCalculation()
    7.         Dim sWriter As StreamWriter
    8.         Dim strTemp As String
    9.         Dim arrTemp(19) As Double
    10.         Dim arrDev As Array
    11.         Dim i, j As Integer
    12.  
    13.         'This bit is to create two file in the temp directory for use, then store the name of the file for
    14.         'furture ADO.Net Use.
    15.         tempFileBaseLoad = CreateTempFile()  'create a new temp file for use....
    16.         FileBaseLoadname = tempFileBaseLoad.Substring(tempPathString.Length, tempFileBaseLoad.Length - tempPathString.Length)
    17.         tempFileMSG = CreateTempFile() 'create a new temp file for use....
    18.         FileMSGname = tempFileMSG.Substring(tempPathString.Length, tempFileMSG.Length - tempPathString.Length)
    19.  
    20.  
    21.         'Need to delete the old files if they exist
    22.         Try
    23.             If IO.File.Exists(tempFileBaseLoad) = True Then
    24.                 File.Delete(tempFileBaseLoad)
    25.             End If
    26.             If IO.File.Exists(tempFileMSG) = True Then
    27.                 File.Delete(tempFileMSG)
    28.             End If
    29.         Catch ex As Exception
    30.         End Try
    31.         sWriter = IO.File.CreateText(tempFileBaseLoad)
    32.         sWriter.WriteLine("Time,GTload,Dev1,Dev2,Dev3,Dev4,Dev5,Dev6,Dev7,Dev8,Dev9,Dev10,Dev11,Dev12,Dev13,Dev14,Dev15,Dev16,Dev17,Dev18")
    33.         sWriter.Close()
    34.         sWriter = IO.File.CreateText(tempFileMSG)
    35.         sWriter.WriteLine("Time,GTload,Dev1,Dev2,Dev3,Dev4,Dev5,Dev6,Dev7,Dev8,Dev9,Dev10,Dev11,Dev12,Dev13,Dev14,Dev15,Dev16,Dev17,Dev18")
    36.         sWriter.Close()
    37.         Dim progressCounter, progressIncrement As Single
    38.         progressIncrement = 100 / dt.Rows.Count
    39.         Dim prog As ProgressBar
    40.         prog = CRSC.progBar1
    41.  
    42.  
    43.         For j = 1 To dt.Rows.Count - 1
    44.             Application.DoEvents()
    45.             For i = 0 To 19
    46.                 arrTemp(i) = dt.Rows(j)(i)
    47.             Next
    48.             strTemp = CanDeviation(arrTemp)
    49.             If arrTemp(1) >= 200 Then    'checks if it is at baseload
    50.                 sWriter = IO.File.AppendText(tempFileBaseLoad)
    51.             Else
    52.                 sWriter = IO.File.AppendText(tempFileMSG)
    53.             End If
    54.             sWriter.WriteLine(strTemp)
    55.             sWriter.Close()
    56.             progressCounter += progressIncrement
    57.             prog.Value = progressCounter
    58.         Next
    59.  
    60.     End Function
    61.     Function CanDeviation(ByRef arrInput As Array) As String
    62.         Dim i As Integer
    63.         Dim arrOutput(19) As Single
    64.         Dim sngCanTempSum As Single
    65.         Dim sngCanAverage As Single
    66.         Dim strTemp As String
    67.  
    68.  
    69.         For i = 2 To 19
    70.             sngCanTempSum += arrInput(i)
    71.         Next
    72.  
    73.         'Now we have the total can Temp
    74.         sngCanAverage = sngCanTempSum / 18
    75.         'Divide by 18 to get can average temp
    76.  
    77.         For i = 0 To 1  'Put the Time and GTload back in
    78.             arrOutput(i) = arrInput(i)
    79.         Next
    80.  
    81.         For i = 2 To 19 'Now get the deviation from mean
    82.             arrOutput(i) = ((arrInput(i) - sngCanAverage) / sngCanAverage) * 100
    83.         Next
    84.  
    85.         For i = 0 To arrOutput.Length - 1
    86.             strTemp &= arrOutput(i) & ","
    87.         Next
    88.         Return strTemp
    89.     End Function
    90. End Module

    I have a progressBar which is called progBar1 on the frmMain and i need to access it from my module. However, it throws up the following error,

    VB Code:
    1. An unhandled exception of type 'System.NullReferenceException' occurred in CRS Creator.exe
    2.  
    3. Additional information: Object reference not set to an instance of an object.

    Any ideas? I know i can pass the control from the main form when i call up the function ..
    Last edited by dinosaur_uk; Feb 2nd, 2005 at 12:01 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
  •  



Click Here to Expand Forum to Full Width