从VBA中的函数返回一个数组

时间:2016-06-22 20:56:53

标签: excel vba

我想编写一个接受数组作为参数的函数。然后该函数填充一些元素。最后,函数填充的数组从调用者可见。

        $user_id = $this->uri->segment(2);
        $user_name = $this->uri->segment(3);


            $query = $this->db->get_where('aoa_user', array('id' => $user_id, 'username' => $user_name));       
            foreach ($query->result() as $row){ 

                $f_name = $row->f_name;             
                $l_name = $row->l_name;             
                $full_name = $row->full_name;               
                $username = $row->username;             
                $alias_name = $row->alias_name;             
                $gender = $row->gender;             
                $country = $row->country;               
                $avatar = $row->avatar;             
                $cover_photo = $row->cover_photo;   
                $email = $row->email;   
                $skill = $row->skill;   
                $other_skills = $row->other_skills; 
                $ex_time = $row->ex_time;   
                $about = $row->about;   
                $company = $row->company;   
                $company_position = $row->company_position; 
                $phone = $row->phone;   
                $facebook = $row->facebook; 
                $facebook_page = $row->facebook_page;   
                $google_plus = $row->google_plus;   
                $twitter = $row->twitter;   
                $youtube = $row->youtube;   
                $skype = $row->skype;   
                $linkedin = $row->linkedin;                     
                $website = $row->website;   
                $latitude = $row->latitude; 
                $longitude = $row->longitude;   
                $verification = $row->verification; 

            }

        $strength_point = 0;

        if($f_name){$strength_point++;} 
        if($l_name){$strength_point + 2;}   
        if($full_name){$strength_point + 2;}    
}

我查看了以下帖子,但没有得到它,不知何故问题不一样。

return array from function in VBA

1 个答案:

答案 0 :(得分:2)

一种解决方案是只传递数组ByRef

Sub main1()
    Dim A(1, 3) As String
    Call F(A)
    Debug.Print A(1, 1)
End Sub
Sub F(ByRef x() As String)
    x(1, 1) = 3.14
End Sub