TypeCode

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • DragonLord
    New Member
    • Mar 2007
    • 122

    #31
    Ah see I learned something new today, thank-you so much for your patience. However, I must have the wrong one because it doesn't contain any of the methods the old code is using lol.
    Last edited by Killer42; Nov 1 '07, 08:52 PM.

    Comment

    • DragonLord
      New Member
      • Mar 2007
      • 122

      #32
      Ok another vb convertion messup....

      if (!(input[x]==null)) <---------------

      where input is a string array ...... ref string input[]

      it keeps telling me it is a variable in the if statement used as a method, i understand what it is doing however i am not sure how to correct the implementation.

      Comment

      • Plater
        Recognized Expert Expert
        • Apr 2007
        • 7872

        #33
        What is the VB code and what is the proposed C# code?

        if (!(input[x]==null))
        would be more likely written as:
        if (input[x]!=null)

        provided that input is an array:
        <sometype>[] input = new <sometype>[<size>];

        Comment

        • DragonLord
          New Member
          • Mar 2007
          • 122

          #34
          [font=Arial]Below is another issue, basically everything i can work with except the [/font]

          The Dim statement I am not sure what it is doing with rawFields() is this not a method of runction... it is pulled from the Utilities.Text. Parsing namespace...


          [font=Arial] Private Function GetFieldArray(B yVal fileRecord As String) As Array
          Dim fields As Array = Nothing
          Select Case Me.FileType
          Case FileFormat.Deli mited
          ' split the fields
          Dim rawFields() As String = fileRecord.Spli t(Convert.ToCha r(Me.Delimiter) )
          ' recombine any with quotes
          RecombineQuoted Fields(rawField s)
          ' remove the extra elements
          ExtractNullArra yElements(rawFi elds, fields)
          Case FileFormat.Fixe dWidth
          Dim rawFields As New ArrayList
          Dim mark As Int32 = 0
          For x As Int32 = 0 To _textFields.Cou nt - 1
          ' extract the value and move the book mark
          rawFields.add(f ileRecord.Subst ring(mark, _textFields(x). Length))
          mark += _textFields(x). Length
          Next[/font]
          [font=Arial] fields = rawfields.ToArr ay
          Case Else
          Throw New ApplicationExce ption("The specified FileType is not valid.")
          End Select
          Return fields
          End Function[/font]

          Comment

          • Plater
            Recognized Expert Expert
            • Apr 2007
            • 7872

            #35
            I think there were some types on that (you had two objects called rawFields and no object called _textFields)

            Code:
            private Array GetFieldArray(string fileRecord) 
            { 
                Array fields = null; 
                switch (this.FileType) 
                { 
                    case FileFormat.Delimited: 
                        // split the fields 
                        string[] _textFields= fileRecord.Split(Convert.ToChar(this.Delimiter)); 
                        // recombine any with quotes 
                        RecombineQuotedFields(rawFields); 
                        // remove the extra elements 
                        ExtractNullArrayElements(rawFields, fields); 
                        break; 
                    case FileFormat.FixedWidth: 
                        ArrayList rawFields = new ArrayList(); 
                        Int32 mark = 0; 
                        for (Int32 x = 0; x <= _textFields.Count - 1; x++) 
                        { 
                            // extract the value and move the book mark 
                            rawFields.add(fileRecord.Substring(mark, _textFields[x].Length)); 
                            mark += _textFields[x].Length; 
                        } 
            
                        fields = rawfields.ToArray(); 
                        break; 
                    default: 
                        throw new ApplicationException("The specified FileType is not valid."); 
                        break; 
                } 
                return fields; 
            }

            Comment

            • DragonLord
              New Member
              • Mar 2007
              • 122

              #36
              One more issue I borrowed some files from another application and brought them inhouse under the same namespace (Good Idea? Bad Idea? not sure )

              but regardless I have everything working except ......

              TextFieldParser tfp;
              //string filePath = Path.Combine(Pa th.GetDirectory Name(Applicatio n.ExecutablePat h), "Delimited.txt" );
              string filepath = myFilePath;
              tfp = new TextFieldParser (myFilePath);
              TextFieldCollec tion fields = new TextFieldCollec tion();
              fields.Add(new TextField("Stat ion", TypeCode.String , true));
              fields.Add(new TextField("Refe rence", TypeCode.String , true));
              fields.Add(new TextField("Name ", TypeCode.String , true));
              fields.Add(new TextField("Addr ess 1", TypeCode.String , true));
              fields.Add(new TextField("Adre ss 2", TypeCode.String , true));
              fields.Add(new TextField("City ", TypeCode.String , true));
              fields.Add(new TextField("ST", TypeCode.String , true));
              fields.Add(new TextField("ZIP" , TypeCode.Int32) );
              fields.Add(new TextField("PH", TypeCode.Int32) );
              fields.Add(new TextField("Alt. PH", TypeCode.Int32) );
              fields.Add(new TextField("Wayb ill", TypeCode.String , true));
              fields.Add(new TextField("Note s 1", TypeCode.String , true));
              fields.Add(new TextField("Note s 2", TypeCode.String , true));
              fields.Add(new TextField("Date ", TypeCode.String , true));
              tfp.TextFields = fields;


              [BOLD] tfp.RecordFaile d += new RecordFailedHan dler(tfp_Record Failed); [/BOLD]

              This line throws an error no matter where it is daying "does not exist in current context" should i change the namespace back to the orginal and just include it with the using clause or is there a way to fix this as is???

              Comment

              • Plater
                Recognized Expert Expert
                • Apr 2007
                • 7872

                #37
                Code:
                tfp.RecordFailed += new RecordFailedHandler(tfp_RecordFailed);
                Is how you attach event handlers. This is looking for the function called "tfp_RecordFail ed" so it can use it for the RecordFailed event.
                You will need to copy that function over as well.

                Comment

                • DragonLord
                  New Member
                  • Mar 2007
                  • 122

                  #38
                  Thanks I am learning alot with this little project of mine,


                  one more question in c# what is the best way to get the ascii value of a char(x)

                  Comment

                  • Plater
                    Recognized Expert Expert
                    • Apr 2007
                    • 7872

                    #39
                    Maybe I am thinking to fast but this should work:
                    Code:
                    char mychar='x';
                    int asciivalue=(int)mychar;

                    Comment

                    • DragonLord
                      New Member
                      • Mar 2007
                      • 122

                      #40
                      [font=Arial]
                      Orginal VB.NET

                      Dim OrderNo As Integer = -1
                      Dim param As SqlParameter = CreateParameter ("@lNewOrderID" , SqlDbType.Int, OrderNo, ParameterDirect ion.Output)
                      ExecuteNonQuery ("sp_TracksOrde rs_Import", CreateParameter ("@xsDetails ", SqlDbType.VarCh ar, xmlStr, 6000), _
                      param)
                      OrderNo = param.Value
                      Return OrderNo

                      VB.NET Function

                      Protected Sub ExecuteNonQuery (ByVal procName As String, ByVal ParamArray paramList() As IDataParameter)
                      Dim cmd As SqlCommand = Nothing
                      ExecuteNonQuery (cmd, procName, paramList)
                      End Sub


                      problem is when i convert this to C# it is not creating a parameter list and instead goes to another fucntion that is an overload with 3 parameters.

                      any thoughts how to redo this in c#.. basically i just need guidence on passing it with a parameter list


                      i.e.

                      ExecuteNonQuery ("sp_TracksOrde rs_Import", parmeterlist??)[/font]

                      Comment

                      • Plater
                        Recognized Expert Expert
                        • Apr 2007
                        • 7872

                        #41
                        [code=vbnet]
                        Protected Sub ExecuteNonQuery (ByVal procName As String, ByVal ParamArray paramList() As IDataParameter)
                        [/code]

                        This should be like:
                        Code:
                        protected void ExecuteNonQuery(string procName, params IDataParameter[] ParamArray)

                        Comment

                        • DragonLord
                          New Member
                          • Mar 2007
                          • 122

                          #42
                          Sorry I was referring to the function call.


                          ExecuteNonQuery ("sp_TracksOrde rs_Import", CreateParameter ("@xsDetails ", SqlDbType.VarCh ar, xmlStr, 6000), _
                          param)

                          This comes from a different class calling the ExecuteNonQuere y as you described above but as you can see it has or at least it thinks it has 3 parameters instead of a string and a parameter list...

                          this ends up going straight to another overload function ExecuteNonQuery (cmd,procname,p aramlist)

                          any thoughts?

                          Comment

                          • Plater
                            Recognized Expert Expert
                            • Apr 2007
                            • 7872

                            #43
                            This call:
                            Code:
                            ExecuteNonQuery("sp_TracksOrders_Import", CreateParameter("@xsDetails", SqlDbType.VarChar, xmlStr, 6000), _param)
                            certainly seems like it fits into the (string, params[]) format to me?


                            Code:
                            IDataParameter temp =CreateParameter("@xsDetails", SqlDbType.VarChar, xmlStr, 6000);
                            //somewhere else another IDataParameter is defined as "param"
                            ExecuteNonQuery("sp_TracksOrders_Import", temp,param);
                            That would call that ExecuteNonQuery (string, params IDataParameter[] myparams); function?

                            Comment

                            • DragonLord
                              New Member
                              • Mar 2007
                              • 122

                              #44
                              Thanks I found the problem because of that post, turns out the translator i used went and put



                              sqlparameter param = xxxxxx

                              and that was where the problem was arrising once i did it as above it corrected the problem now i have to troubleshoot the connection lol... it just never ends!!!

                              Comment

                              • DragonLord
                                New Member
                                • Mar 2007
                                • 122

                                #45
                                Ok one more question

                                I am new to event handling in C# and here is the situation

                                I believe I have all the parts, I have the deligate named recordhandler
                                the class with the ations to be taken

                                in the class that is calling it though (rasing the event so to speak) how to i tell it to call it.

                                if (RecordFound != null)
                                RecordFound(ref currentLineNumb er, m_TextFieldSche ma.TextFields);
                                m_CurrentLineNu mber = currentLineNumb er;



                                Record found in the try block is always null even though it is doing it's thing... how do i tell it before it gets to the if statement that a record was found?

                                Thanks
                                Dale.
                                [/size]

                                Comment

                                Working...