Alpha Software Mobile Development Tools:   Alpha Anywhere    |   Alpha TransForm subscribe to our YouTube Channel  Follow Us on LinkedIn  Follow Us on Twitter  Follow Us on Facebook

Announcement

Collapse

The Alpha Software Forum Participation Guidelines

The Alpha Software Forum is a free forum created for Alpha Software Developer Community to ask for help, exchange ideas, and share solutions. Alpha Software strives to create an environment where all members of the community can feel safe to participate. In order to ensure the Alpha Software Forum is a place where all feel welcome, forum participants are expected to behave as follows:
  • Be professional in your conduct
  • Be kind to others
  • Be constructive when giving feedback
  • Be open to new ideas and suggestions
  • Stay on topic


Be sure all comments and threads you post are respectful. Posts that contain any of the following content will be considered a violation of your agreement as a member of the Alpha Software Forum Community and will be moderated:
  • Spam.
  • Vulgar language.
  • Quotes from private conversations without permission, including pricing and other sales related discussions.
  • Personal attacks, insults, or subtle put-downs.
  • Harassment, bullying, threatening, mocking, shaming, or deriding anyone.
  • Sexist, racist, homophobic, transphobic, ableist, or otherwise discriminatory jokes and language.
  • Sexually explicit or violent material, links, or language.
  • Pirated, hacked, or copyright-infringing material.
  • Encouraging of others to engage in the above behaviors.


If a thread or post is found to contain any of the content outlined above, a moderator may choose to take one of the following actions:
  • Remove the Post or Thread - the content is removed from the forum.
  • Place the User in Moderation - all posts and new threads must be approved by a moderator before they are posted.
  • Temporarily Ban the User - user is banned from forum for a period of time.
  • Permanently Ban the User - user is permanently banned from the forum.


Moderators may also rename posts and threads if they are too generic or do not property reflect the content.

Moderators may move threads if they have been posted in the incorrect forum.

Threads/Posts questioning specific moderator decisions or actions (such as "why was a user banned?") are not allowed and will be removed.

The owners of Alpha Software Corporation (Forum Owner) reserve the right to remove, edit, move, or close any thread for any reason; or ban any forum member without notice, reason, or explanation.

Community members are encouraged to click the "Report Post" icon in the lower left of a given post if they feel the post is in violation of the rules. This will alert the Moderators to take a look.

Alpha Software Corporation may amend the guidelines from time to time and may also vary the procedures it sets out where appropriate in a particular case. Your agreement to comply with the guidelines will be deemed agreement to any changes to it.



Bonus TIPS for Successful Posting

Try a Search First
It is highly recommended that a Search be done on your topic before posting, as many questions have been answered in prior posts. As with any search engine, the shorter the search term, the more "hits" will be returned, but the more specific the search term is, the greater the relevance of those "hits". Searching for "table" might well return every message on the board while "tablesum" would greatly restrict the number of messages returned.

When you do post
First, make sure you are posting your question in the correct forum. For example, if you post an issue regarding Desktop applications on the Mobile & Browser Applications board , not only will your question not be seen by the appropriate audience, it may also be removed or relocated.

The more detail you provide about your problem or question, the more likely someone is to understand your request and be able to help. A sample database with a minimum of records (and its support files, zipped together) will make it much easier to diagnose issues with your application. Screen shots of error messages are especially helpful.

When explaining how to reproduce your problem, please be as detailed as possible. Describe every step, click-by-click and keypress-by-keypress. Otherwise when others try to duplicate your problem, they may do something slightly different and end up with different results.

A note about attachments
You may only attach one file to each message. Attachment file size is limited to 2MB. If you need to include several files, you may do so by zipping them into a single archive.

If you forgot to attach your files to your post, please do NOT create a new thread. Instead, reply to your original message and attach the file there.

When attaching screen shots, it is best to attach an image file (.BMP, .JPG, .GIF, .PNG, etc.) or a zip file of several images, as opposed to a Word document containing the screen shots. Because Word documents are prone to viruses, many message board users will not open your Word file, therefore limiting their ability to help you.

Similarly, if you are uploading a zipped archive, you should simply create a .ZIP file and not a self-extracting .EXE as many users will not run your EXE file.
See more
See less

Excel OLE Check for Empty Cell

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Excel OLE Check for Empty Cell

    I'm writing a script that parses an Excel file to import data into my database and am having difficulty figuring out how to check for an empty cell.

    I tried doing a loop such as the following:

    Code:
    While currentCell <> ""
       'Do stuff
    End While
    However, every time I loop to an empty cell I get an error stating "Argument is incorrect data type (NIL)"

    Thanks for any help!

    #2
    Re: Excel OLE Check for Empty Cell

    Well, once I posted the thread, I found a solution in one of the related posts below the thread.

    From this post: http://msgboard.alphasoftware.com/al...ad.php?t=66096

    Selwyn suggested using eval_Valid to check for the error. So essentially, whenever I was checking for a value in a cell, I would make sure the statement was valid. If I was going to receive a "NIL" error, the eval_valid function would catch it.

    Comment


      #3
      Re: Excel OLE Check for Empty Cell

      Try

      While currentCell.value <> ""
      'Do stuff
      End While
      There can be only one.

      Comment


        #4
        Re: Excel OLE Check for Empty Cell

        Wrong thread, sorry.
        Last edited by Stan Mathews; 01-27-2009, 12:30 PM.
        There can be only one.

        Comment


          #5
          Re: Excel OLE Check for Empty Cell

          Stan - That works perfectly! When I was referencing a cell in Excel, I would still receive a value back without using ".Value" and assumed it was the same functionality.

          Thanks for the help!!

          Comment


            #6
            Re: Excel OLE Check for Empty Cell

            You wouldn't believe how long it took me to figure that out. Glad I could pass it on.
            There can be only one.

            Comment


              #7
              Re: Excel OLE Check for Empty Cell

              I can believe it... I've been at this for a few days now and would've been at it even longer! I really appreciate it!

              One final question for you: Do you know of any good resources for Excel OLE methods and functions? I've been scouring the internet with Google trying to find information and am successful most of the time but I haven't been able to find a one-stop-shop for all things Excel OLE.

              Thanks again Stan!

              Comment


                #8
                Re: Excel OLE Check for Empty Cell

                My best source of help, after I got a good push from Marcel, is to create a simple macro in excel doing what I want to be able to tell Alpha to do. I then look at the vb behind the macro and work out how to translate that into xbasic.

                You can determine the numeric values of excel constants in the vb immediate window.

                Code:
                ? xlAscending
                 1
                ? xldescending
                 2
                There are still some areas that I haven't been able to make work even though the implementation seems simple enough.

                This

                Code:
                Range("A1:B6").Select
                    Selection.Sort Key1:=Range("B1"), Order1:=xlAscending, Header:=xlGuess, _
                        OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
                        DataOption1:=xlSortNormal
                Should translate to (given the xlapp pointer to the ole object

                xlApp.Range("A1:B6").Select()
                xlApp.Selection.Sort(Range("B1"),1,0,1,.F.,1,0)

                but it doesn't work for me.

                (Selects the range A1:B6 and sorts ascending on column B)
                Last edited by Stan Mathews; 01-27-2009, 01:50 PM.
                There can be only one.

                Comment


                  #9
                  Re: Excel OLE Check for Empty Cell

                  Hi Stan,

                  Found a solution for the sort problem. The .Sort() command is a fully optional construction, see the Excel help. In VBA you can use two ways of declaring your parameters, 'named' and 'unnamed'. The named version is that every parameter has it name such as:
                  Code:
                  Key1:=Range("B1")
                  and even the order in which you name them is free.

                  The other way is the "in order" parameter list. If you study the .sort() method you will see that is can be used for different types of data: ranges, cell, pivot-table, named ranges. What I did is starting with a full parameter list and deleted each last parameter until there was no error message and the sort worked. I think that Xbasic can't handle the optional part of the declaration list and when the parameters doesn't align anymore it produces an error.
                  Code:
                  'xlApp.Selection.Sort(xlApp.Range("A1"),1,xlApp.Range("A1"),2,xlApp.Range("A1"),1,0,1,.F.,1,0,0,0)
                  I ended up with the next line of code. Only the first three parameters will align without an error.
                  Code:
                  xlApp.Selection.Sort(xlApp.Range("A1"),1,xlApp.Range("B1"))
                  and are accepted when you run the code. But the last parameter range doesn't add any positive result to the sort so ommit this. Therefore you can only sort on one column in the selected range and the selection is includes in the sort.

                  Solution:
                  Code:
                  dim xlApp as p
                  xlApp = ole.GetObject("","Excel.Application.11")
                  xlApp.Range("A1:C8").select()
                  xlApp.Selection.Sort(xlApp.Range("A1"),1)
                  Marcel

                  I hear and I forget. I see and I remember. I do and I understand.
                  ---- Confusius ----

                  Comment


                    #10
                    Re: Excel OLE Check for Empty Cell

                    Marcel,

                    Thanks for that. I'll go try an implementation now.

                    Haven't heard much from you lately. Hope all is well.

                    Stan
                    There can be only one.

                    Comment


                      #11
                      Re: Excel OLE Check for Empty Cell

                      Most excellent, Marcel.

                      Code:
                      FUNCTION excel_sort AS L (excelname AS C, newname AS C, sortcol AS C, direct as N)
                      	IF (.not. between(sortcol,"A","Z"))
                      		ui_msg_box("Error","Can only sort on col A-Z")
                      		exit FUNCTION
                      	END IF
                      	IF (.not. between(direct,1,2))
                      		ui_msg_box("Error","Can only sort ascend (1) or descend (2)")
                      		exit FUNCTION
                      	END IF
                      	Dim xlApp as p
                      	Dim myCell as c
                      	xlApp = ole.Create("Excel.Application")
                      	xlApp.Workbooks.Open(excelname)
                      	'xlApp.Visible = .T. 'comment this line out if you don't want to see Excel
                      	topleft = "A1"
                      	lastrow = xlApp.Activecell.SpecialCells("11").Row
                      	lastcol = xlApp.Activecell.SpecialCells("11").Column
                      	lastcell = chr(lastcol+64)+lastrow
                      	myrange = topleft+":"+lastcell
                      	xlApp.Range(myrange).Select()
                      	mysort = sortcol+"1"
                      	xlApp.Selection.Sort(xlapp.Range(mysort),direct)
                      	xlapp.DisplayAlerts = .F.
                      	xlApp.ActiveWorkbook.SaveAs(newname,-4143) '-4143 is a constant for Excel Normal, dbf4 is 11
                      	xlApp.Workbooks.Close()
                      	xlApp.DisplayAlerts = .T.
                      	xlApp.Quit()
                      	delete xlApp
                      END FUNCTION
                      
                      'to call the function, use the example on the next line
                      'excel_sort("c:\test1.xls","c:\test2.xls","C",2) 
                      'this sorts the active area of spreadsheet test1.xls on column C, descending
                      'then saves that as test2.xls
                      There can be only one.

                      Comment


                        #12
                        Re: Excel OLE Check for Empty Cell

                        You did an excellent job too Stan with your sort function. I can learn a lot from your Xbasic code how you handle things in Excel.
                        Marcel

                        I hear and I forget. I see and I remember. I do and I understand.
                        ---- Confusius ----

                        Comment


                          #13
                          Re: Excel OLE Check for Empty Cell

                          The A-Z column restriction was a shortcut. I have a function somewhere that will translate the lastcol numeric value into the character equivalent for combination with the lastrow numeric value to yield the correct values for lastcell like AA1 and above. Just don't use it much and didn't feel like looking it up.

                          Thanks for the kind words.
                          There can be only one.

                          Comment


                            #14
                            Re: Excel OLE Check for Empty Cell

                            Found the conversion of excel column number to letter(s). Sort restriction altered.

                            Code:
                            FUNCTION excel_sort AS L (excelname AS C, newname AS C, sortcol AS C, direct as N)
                            	IF (.not. between(sortcol,"A","IV"))'max xl 2003
                            		ui_msg_box("Error","Can only sort on col A-IV")
                            		exit FUNCTION
                            	END IF
                            	IF (.not. between(direct,1,2))
                            		ui_msg_box("Error","Can only sort ascend (1) or descend (2)")
                            		exit FUNCTION
                            	END IF
                            	Dim xlApp as p
                            	Dim myCell as c
                            	xlApp = ole.Create("Excel.Application")
                            	xlApp.Workbooks.Open(excelname)
                            	'xlApp.Visible = .T. 'comment this line out if you don't want to see Excel
                            	topleft = "A1"
                            	lastrow = xlApp.Activecell.SpecialCells("11").Row
                            	lastcol = xlApp.Activecell.SpecialCells("11").Column
                            	lastcell = xlindx_to_txt(lastcol)+lastrow
                            	myrange = topleft+":"+lastcell
                            	xlApp.Range(myrange).Select()
                            	mysort = sortcol+"1"
                            	xlApp.Selection.Sort(xlapp.Range(mysort),direct)
                            	xlapp.DisplayAlerts = .F.
                            	xlApp.ActiveWorkbook.SaveAs(newname,-4143) '-4143 is a constant for Excel Normal, dbf4 is 11
                            	xlApp.Workbooks.Close()
                            	xlApp.DisplayAlerts = .T.
                            	xlApp.Quit()
                            	delete xlApp
                            	excel_normal = .t.
                            END FUNCTION
                            
                            'to call the function, use the example on the next line
                            'excel_sort("c:\test1.xls","c:\test2.xls","C",2) 
                            'this sorts the active area of spreadsheet test1.xls on column C, descending
                            'then saves that as test2.xls
                            
                            FUNCTION xlindx_to_txt AS C (colnum AS N )
                              If Colnum > 26 Then
                                xlindx_to_txt = Chr(Int((Colnum - 1) / 26) + 64) + Chr((mod((Colnum - 1),26) ) + 65)
                              Else
                                xlindx_to_txt = Chr(Colnum + 64)
                              End If
                            END FUNCTION
                            There can be only one.

                            Comment


                              #15
                              Re: Excel OLE Check for Empty Cell

                              Stan, Marcel,

                              Thanks for this.
                              It makes a Very nice addition to my help file for methods to use for Excel.
                              Mike
                              __________________________________________
                              It is only when we forget all our learning that we begin to know.
                              It's not what you look at that matters, it's what you see.
                              Henry David Thoreau
                              __________________________________________



                              Comment

                              Working...
                              X